SlideShare uma empresa Scribd logo
1 de 24
Baixar para ler offline
Want to write a book
in Jupyter - here’s how
Dr Jim Arlow, Clear View Training Limited

www.clearviewtraining.com
1
Introduction
• In this presentation, we will demonstrate how to use
Jupyter notebooks to deliver interactive long form text
such as books

• We will quickly take a look at some common options for
creating interactive text, and then go to develop a set of
requirements and tools for using Jupyter as an authoring
platform for books
2
About the author
• Jim Arlow is an independent consultant,
trainer and author working in OO analysis
and design, UML modelling, BPMN,
Metadata Management, Model Driven
Architecture (MDA), requirements
engineering and software engineering
process design and implementation

• He is author of the best selling, “UML 2
and the Unified Process”, and you can
find a list of all of his books here:
www.clearviewtraining.com

• Contact:

• www.clearviewtraining.com

• https://www.linkedin.com/in/jimarlow
3
Check out my latest book!
http://bit.ly/SecretsOfAnalysis
Options for writing long-
form interactive texts
• It is quite surprising how few platforms there are that are easy to use
for creating interactive long-form texts!

• We have direct experience with:

• Apple iBooks Author

• Mathematica 

• Jupyter

• Of course, you can always use HTML, but that is a complex option…

• Frameworks and libraries for interactivity 

• Hosting mechanisms and distribution

• Etc. etc.
4
Apple iBooks Author
• Creates truly beautiful interactive
books!

• Simple and fun to use!

• Built in interactive widgets are limited
(e.g. quizzes, interactive graphics etc.)

• Hard to create custom interactive
widgets using HTML5

• Can’t include live code

• Limited distribution - does anyone
actually use the Apple Books Store?
http://bit.ly/IntroductionToBPMN2
5
Check it out!
Mathematica
• Insanely powerful and elegant!

• Easy to use authoring environment with
full mathematical notation and live code

• Very rich interactivity via the Manipulate
command and more

• Licensing to sell books is prohibitively
costly for small authors/publishers

• Distribution via Mathematica viewer (free)
is to be phased out and replaced by
deployment on a website (costly) - no
sensible option left for free books
http://bit.ly/2DBoBnC
6
Jupyter
• Many of the advantages of Mathematica
but with open source licensing

• Live Python code (the default) has more
traction than live Mathematica code

• Good support for interactive widgets via
interact functions

• Many options for deployment

• Many options for live code

• More popular than Mathematica??

• How do you package and sell Jupyter
Notebooks?
7
What is Jupyter?
• From the Jupyter website http://jupyter.org/index.html:

• “The Jupyter Notebook is an open-source web application that
allows you to create and share documents that contain:

• Live code

• Equations

• Visualisations

• Narrative text

• Interactive widgets

• Uses include: data cleaning and transformation, numerical
simulation, statistical modelling, data visualisation, machine
learning, and much more”.
8
How Jupyter works
• Server runs notebook code (usually Python) and serves
up static HTML and dynamic interactive widgets to the
client web browser
Interactive
Computing
Protocol
Jupyter Notebook Server
NB1
Code
Text
Data
Widgets
NB2
Code
Text
Data
Widgets
NB3
Code
Text
Data
Widgets
Browser
9
Jupyter for books
• Books shall be delivered as a sequence of Jupyter
notebooks, one per chapter

• Each chapter shall build on the previous one (so we need
to reuse code between chapters)

• A reusable code base shall be extracted from book

• Each chapter shall have a table of contents (TOC) 

• Each section shall have a link back to the TOC

• The whole book shall have a table of contents
10
Jupyter book structure
• A book comprises several chapters with one Jupyter notebook per
chapter e.g. C1.ipynb
• Notebooks allow headings and sub headings

• Each chapter builds on the previous one and needs to reuse its code

• Export of code is done using the nbconvert utility (see later)
C1.ipynb
C1.py
C2.ipynb
Convert
import
C3.ipynb
C3.py
C4.ipynb
Convert
import
C2.py
Convert
import
nbconvert
Reusable
code
11
Jupyter
Notebooks
Convert
C4.py
Python import
Two types of code…
1. Reusable code must be factored out for use in
subsequent chapters and elsewhere:

• Python classes

• Functions

• Global variables etc.

2. Non-reusable (demo) code that needs to be constrained
to execution within a notebook:

• Interactive demonstration code

• Static output such as tables
12
Reusable and non-reusable code
Reusable
function
Non-reusable
(demo) code
Interactive
widgets
Need to
remove all non-
reusable code
13
Identifying demo code
• This is code that should not be reused outside of the notebook!

• By convention: begin each demo code cell with #Demo and end it with #Demo

• By metadata: add the DEMO tag to each demo code cell so that it can be
identified and removed later

• Open the View:Cell toolbar:Tags menu to see the tags associated with each cell
We will use DEMO to
filter out this cell using
nbconvert
14
Extracting the code…
• Filter the notebooks using the nbconvert utility to discard:

• Markup, graphics, cell inputs, outputs and prompts

• Demo code - remove all cells with the tag DEMO with the
option: 

--TagRemovePreprocessor.remove_cell_tags={"DEMO"}
!jupyter nbconvert --to python 

--TemplateExporter.exclude_input_prompt=True 

--TemplateExporter.exclude_output_prompt=True 

--TemplateExporter.exclude_output=True 

--TemplateExporter.exclude_markdown=True 

--TagRemovePreprocessor.remove_cell_tags={"DEMO"} 

Introduction Pitch MusicalSetTheory MusicalSetTheory2 Scales
Reusable
Python Code
Reusable
Python Code
Reusable
Python Code
Scales.py
Reusable Code
nbconvert (executed in a Jupyter cell)
15
What we have achieved…
• Books shall be delivered as a sequence of Jupyter
notebooks, one per chapter

• Each chapter shall build on the previous one (so we need
to reuse code between chapters)

• A reusable code base shall be extracted from book

• Each chapter needs a table of contents (TOC) and
navigation from each section back to the TOC

• The book as a whole needs a table of contents
16
Chapter TOC
• Jupyter notebooks are missing an important feature - the
ability to automatically generate a table of contents, so we will
handcraft a solution!

• Mark up TOC entries by convention:

• The first line in a markdown cell shall be a candidate TOC
entry

• A TOC entry line shall begin with one or more # 

• A TOC entry line shall end with a single #

• Note: We could have used tags again, but this markup
convention is much easier!

• Extract marked up TOC entries and generate TOC in notebook
17
Example TOC entry
Ends with #Begins with #
First line
18
Extracting the TOC entries
• Jupyter notebooks are JSON documents that have a
hierarchical structure

• This means that it is relatively easy to parse them to
extract information
JSON Notebook Data
cell
source
cell
If first line of source looks like
“# …#”
“## …#”
etc.
Add to TOC
Notebook
with TOC
19
Load notebook as JSON
Find TOC entry convention
Generate markup hyperlinks for an
indented list of headings
Embed TOC in current notebook
HTML anchor TOC
TocTools.py
Include this module in
your notebooks
20
Call function in Jupyter
notebook to embed TOC
Call the function on the
current notebook file to
generate the TOC
The generated TOC
has an anchor so you can
link back to it
This file is Pitch.ipynb
- make sure you call on the
right file!
21
Book TOC
• Ideally, the book TOC should contain a concatenation of all
of the chapter TOCs with active hyperlinks

• For now, we will compromise by limiting the book TOC to a
list of chapters because it is easy to hyperlink to a chapter
to see its contents - we may revisit this decision later!

• The problem is that a normal hyperlink opens a new
instance of the target notebook:
22
Pitch.ipynb
Pitch.ipynb
Pitch.ipynb
Transposition
Open a new
instance
Generating the book TOC
• Just use standard Jupyter hyperlinks that you can generate
from a list of chapters:
23
Summary
• Books shall be delivered as a sequence of Jupyter
notebooks, one per chapter

• Each chapter shall build on the previous one (so we need to
reuse code between chapters)

• A reusable code base shall be extracted from book

• Each chapter shall have a table of contents (TOC) 

• Each section shall have a link back to the TOC

• The whole book shall have a table of contents

• Conclusion: Jupyter is an excellent platform for the delivery
of interactive long-form content!
24

Mais conteúdo relacionado

Mais procurados

Представлення статистичної інформації за допомогою графічного методу
Представлення статистичної інформації за допомогою графічного методуПредставлення статистичної інформації за допомогою графічного методу
Представлення статистичної інформації за допомогою графічного методуOksana Marets
 
редагування даних таблиці 7 клас
редагування даних таблиці 7 класредагування даних таблиці 7 клас
редагування даних таблиці 7 класaniadania
 
Βάσεις Δεδομένων Κεφ3
Βάσεις Δεδομένων Κεφ3Βάσεις Δεδομένων Κεφ3
Βάσεις Δεδομένων Κεφ3marygeorg
 
Βάσεις δεδομένων Κεφ.1
Βάσεις δεδομένων Κεφ.1Βάσεις δεδομένων Κεφ.1
Βάσεις δεδομένων Κεφ.1marygeorg
 
Σύστημα Επικοινωνίας μέσω Ανταλλαγής Εικόνων (Pecs)
Σύστημα Επικοινωνίας μέσω Ανταλλαγής Εικόνων (Pecs)Σύστημα Επικοινωνίας μέσω Ανταλλαγής Εικόνων (Pecs)
Σύστημα Επικοινωνίας μέσω Ανταλλαγής Εικόνων (Pecs)nikbalki
 
διδακτικο σεναριο στη δομή επιλογής
διδακτικο σεναριο στη δομή επιλογήςδιδακτικο σεναριο στη δομή επιλογής
διδακτικο σεναριο στη δομή επιλογήςEffie Tsiabou
 
Схеми та діаграми
Схеми та діаграмиСхеми та діаграми
Схеми та діаграмиOlga Barna
 
Урок 21 для 7 класу - Розробка діалогових програм.
Урок 21 для 7 класу - Розробка діалогових програм.Урок 21 для 7 класу - Розробка діалогових програм.
Урок 21 для 7 класу - Розробка діалогових програм.VsimPPT
 
Mka python jr-urok_04_ua_1563258855
Mka python jr-urok_04_ua_1563258855Mka python jr-urok_04_ua_1563258855
Mka python jr-urok_04_ua_1563258855PavloTsiura
 
Microsoft Access Θεωρία 1/6
Microsoft Access Θεωρία 1/6Microsoft Access Θεωρία 1/6
Microsoft Access Θεωρία 1/6Michael Ntallas
 
Група київських неокласиків, їхнє творче кредо, орієнтири на класичну форму п...
Група київських неокласиків, їхнє творче кредо, орієнтири на класичну форму п...Група київських неокласиків, їхнє творче кредо, орієнтири на класичну форму п...
Група київських неокласиків, їхнє творче кредо, орієнтири на класичну форму п...Iryna Sukhorabska
 
Урок 49 для 8 класу - Відображення базових графічних примітивів – лінія, прям...
Урок 49 для 8 класу - Відображення базових графічних примітивів – лінія, прям...Урок 49 для 8 класу - Відображення базових графічних примітивів – лінія, прям...
Урок 49 для 8 класу - Відображення базових графічних примітивів – лінія, прям...VsimPPT
 
8 геом бабенко_пособ_2008_укр
8 геом бабенко_пособ_2008_укр8 геом бабенко_пособ_2008_укр
8 геом бабенко_пособ_2008_укрAira_Roo
 
A-2_Yλικό_Ανάθεση_Εργασίας
A-2_Yλικό_Ανάθεση_ΕργασίαςA-2_Yλικό_Ανάθεση_Εργασίας
A-2_Yλικό_Ανάθεση_ΕργασίαςElenaX
 
засоби автоматизації процесу створення документа
засоби автоматизації процесу створення документазасоби автоматизації процесу створення документа
засоби автоматизації процесу створення документаElena Kostesnko
 

Mais procurados (20)

Представлення статистичної інформації за допомогою графічного методу
Представлення статистичної інформації за допомогою графічного методуПредставлення статистичної інформації за допомогою графічного методу
Представлення статистичної інформації за допомогою графічного методу
 
8 клас урок 5
8 клас урок 58 клас урок 5
8 клас урок 5
 
3 клас урок 17 що таке комп'ютерна презентація
3 клас урок 17 що таке комп'ютерна презентація3 клас урок 17 що таке комп'ютерна презентація
3 клас урок 17 що таке комп'ютерна презентація
 
редагування даних таблиці 7 клас
редагування даних таблиці 7 класредагування даних таблиці 7 клас
редагування даних таблиці 7 клас
 
Βάσεις Δεδομένων Κεφ3
Βάσεις Δεδομένων Κεφ3Βάσεις Δεδομένων Κεφ3
Βάσεις Δεδομένων Κεφ3
 
Βάσεις δεδομένων Κεφ.1
Βάσεις δεδομένων Κεφ.1Βάσεις δεδομένων Κεφ.1
Βάσεις δεδομένων Κεφ.1
 
Σύστημα Επικοινωνίας μέσω Ανταλλαγής Εικόνων (Pecs)
Σύστημα Επικοινωνίας μέσω Ανταλλαγής Εικόνων (Pecs)Σύστημα Επικοινωνίας μέσω Ανταλλαγής Εικόνων (Pecs)
Σύστημα Επικοινωνίας μέσω Ανταλλαγής Εικόνων (Pecs)
 
διδακτικο σεναριο στη δομή επιλογής
διδακτικο σεναριο στη δομή επιλογήςδιδακτικο σεναριο στη δομή επιλογής
διδακτικο σεναριο στη δομή επιλογής
 
Схеми та діаграми
Схеми та діаграмиСхеми та діаграми
Схеми та діаграми
 
34
3434
34
 
Урок 21 для 7 класу - Розробка діалогових програм.
Урок 21 для 7 класу - Розробка діалогових програм.Урок 21 для 7 класу - Розробка діалогових програм.
Урок 21 для 7 класу - Розробка діалогових програм.
 
Mka python jr-urok_04_ua_1563258855
Mka python jr-urok_04_ua_1563258855Mka python jr-urok_04_ua_1563258855
Mka python jr-urok_04_ua_1563258855
 
Microsoft Access Θεωρία 1/6
Microsoft Access Θεωρία 1/6Microsoft Access Θεωρία 1/6
Microsoft Access Θεωρία 1/6
 
Група київських неокласиків, їхнє творче кредо, орієнтири на класичну форму п...
Група київських неокласиків, їхнє творче кредо, орієнтири на класичну форму п...Група київських неокласиків, їхнє творче кредо, орієнтири на класичну форму п...
Група київських неокласиків, їхнє творче кредо, орієнтири на класичну форму п...
 
Урок 49 для 8 класу - Відображення базових графічних примітивів – лінія, прям...
Урок 49 для 8 класу - Відображення базових графічних примітивів – лінія, прям...Урок 49 для 8 класу - Відображення базових графічних примітивів – лінія, прям...
Урок 49 для 8 класу - Відображення базових графічних примітивів – лінія, прям...
 
Mongo db intro.pptx
Mongo db intro.pptxMongo db intro.pptx
Mongo db intro.pptx
 
Безпечний інтернет 1
Безпечний інтернет 1Безпечний інтернет 1
Безпечний інтернет 1
 
8 геом бабенко_пособ_2008_укр
8 геом бабенко_пособ_2008_укр8 геом бабенко_пособ_2008_укр
8 геом бабенко_пособ_2008_укр
 
A-2_Yλικό_Ανάθεση_Εργασίας
A-2_Yλικό_Ανάθεση_ΕργασίαςA-2_Yλικό_Ανάθεση_Εργασίας
A-2_Yλικό_Ανάθεση_Εργασίας
 
засоби автоматизації процесу створення документа
засоби автоматизації процесу створення документазасоби автоматизації процесу створення документа
засоби автоматизації процесу створення документа
 

Semelhante a Want to write a book in Jupyter - here's how

Python programming lab 23
Python programming lab 23Python programming lab 23
Python programming lab 23profbnk
 
Python indroduction
Python indroductionPython indroduction
Python indroductionFEG
 
Introduction to Jupyter notebook and MS Azure Machine Learning Studio
Introduction to Jupyter notebook and MS Azure Machine Learning StudioIntroduction to Jupyter notebook and MS Azure Machine Learning Studio
Introduction to Jupyter notebook and MS Azure Machine Learning StudioMuralidharan Deenathayalan
 
Introduction to Jupyter notebook and MS Azure Machine Learning Studio
Introduction to Jupyter notebook and MS Azure Machine Learning StudioIntroduction to Jupyter notebook and MS Azure Machine Learning Studio
Introduction to Jupyter notebook and MS Azure Machine Learning StudioMuralidharan Deenathayalan
 
Introduction to Python for Security Professionals
Introduction to Python for Security ProfessionalsIntroduction to Python for Security Professionals
Introduction to Python for Security ProfessionalsAndrew McNicol
 
Programming with Python: Week 1
Programming with Python: Week 1Programming with Python: Week 1
Programming with Python: Week 1Ahmet Bulut
 
Master class in Java in 2018
Master class in Java in 2018Master class in Java in 2018
Master class in Java in 2018Miro Cupak
 
Engage 2019 Software documentation is fun if you have the right tools: Introd...
Engage 2019 Software documentation is fun if you have the right tools: Introd...Engage 2019 Software documentation is fun if you have the right tools: Introd...
Engage 2019 Software documentation is fun if you have the right tools: Introd...AndrewMagerman
 
Master class in modern Java
Master class in modern JavaMaster class in modern Java
Master class in modern JavaMiro Cupak
 
Q-Step_WS_02102019_Practical_introduction_to_Python.pdf
Q-Step_WS_02102019_Practical_introduction_to_Python.pdfQ-Step_WS_02102019_Practical_introduction_to_Python.pdf
Q-Step_WS_02102019_Practical_introduction_to_Python.pdfMichpice
 
Q-Step_WS_02102019_Practical_introduction_to_Python.pptx
Q-Step_WS_02102019_Practical_introduction_to_Python.pptxQ-Step_WS_02102019_Practical_introduction_to_Python.pptx
Q-Step_WS_02102019_Practical_introduction_to_Python.pptxnyomans1
 
Q-SPractical_introduction_to_Python.pptx
Q-SPractical_introduction_to_Python.pptxQ-SPractical_introduction_to_Python.pptx
Q-SPractical_introduction_to_Python.pptxJeromeTacata3
 
web programming Unit VIII complete about python by Bhavsingh Maloth
web programming Unit VIII complete about python  by Bhavsingh Malothweb programming Unit VIII complete about python  by Bhavsingh Maloth
web programming Unit VIII complete about python by Bhavsingh MalothBhavsingh Maloth
 
Master class in modern Java
Master class in modern JavaMaster class in modern Java
Master class in modern JavaMiro Cupak
 
Jupyter notebooks on steroids
Jupyter notebooks on steroidsJupyter notebooks on steroids
Jupyter notebooks on steroidsJose Enrique Ruiz
 

Semelhante a Want to write a book in Jupyter - here's how (20)

Numba Overview
Numba OverviewNumba Overview
Numba Overview
 
Python programming lab 23
Python programming lab 23Python programming lab 23
Python programming lab 23
 
Python indroduction
Python indroductionPython indroduction
Python indroduction
 
Introduction to Jupyter notebook and MS Azure Machine Learning Studio
Introduction to Jupyter notebook and MS Azure Machine Learning StudioIntroduction to Jupyter notebook and MS Azure Machine Learning Studio
Introduction to Jupyter notebook and MS Azure Machine Learning Studio
 
Introduction to Jupyter notebook and MS Azure Machine Learning Studio
Introduction to Jupyter notebook and MS Azure Machine Learning StudioIntroduction to Jupyter notebook and MS Azure Machine Learning Studio
Introduction to Jupyter notebook and MS Azure Machine Learning Studio
 
Introduction_to_Python.pptx
Introduction_to_Python.pptxIntroduction_to_Python.pptx
Introduction_to_Python.pptx
 
Python Demo.pptx
Python Demo.pptxPython Demo.pptx
Python Demo.pptx
 
Introduction to Python for Security Professionals
Introduction to Python for Security ProfessionalsIntroduction to Python for Security Professionals
Introduction to Python for Security Professionals
 
Python Demo.pptx
Python Demo.pptxPython Demo.pptx
Python Demo.pptx
 
Programming with Python: Week 1
Programming with Python: Week 1Programming with Python: Week 1
Programming with Python: Week 1
 
Master class in Java in 2018
Master class in Java in 2018Master class in Java in 2018
Master class in Java in 2018
 
An Introduction to PyPy
An Introduction to PyPyAn Introduction to PyPy
An Introduction to PyPy
 
Engage 2019 Software documentation is fun if you have the right tools: Introd...
Engage 2019 Software documentation is fun if you have the right tools: Introd...Engage 2019 Software documentation is fun if you have the right tools: Introd...
Engage 2019 Software documentation is fun if you have the right tools: Introd...
 
Master class in modern Java
Master class in modern JavaMaster class in modern Java
Master class in modern Java
 
Q-Step_WS_02102019_Practical_introduction_to_Python.pdf
Q-Step_WS_02102019_Practical_introduction_to_Python.pdfQ-Step_WS_02102019_Practical_introduction_to_Python.pdf
Q-Step_WS_02102019_Practical_introduction_to_Python.pdf
 
Q-Step_WS_02102019_Practical_introduction_to_Python.pptx
Q-Step_WS_02102019_Practical_introduction_to_Python.pptxQ-Step_WS_02102019_Practical_introduction_to_Python.pptx
Q-Step_WS_02102019_Practical_introduction_to_Python.pptx
 
Q-SPractical_introduction_to_Python.pptx
Q-SPractical_introduction_to_Python.pptxQ-SPractical_introduction_to_Python.pptx
Q-SPractical_introduction_to_Python.pptx
 
web programming Unit VIII complete about python by Bhavsingh Maloth
web programming Unit VIII complete about python  by Bhavsingh Malothweb programming Unit VIII complete about python  by Bhavsingh Maloth
web programming Unit VIII complete about python by Bhavsingh Maloth
 
Master class in modern Java
Master class in modern JavaMaster class in modern Java
Master class in modern Java
 
Jupyter notebooks on steroids
Jupyter notebooks on steroidsJupyter notebooks on steroids
Jupyter notebooks on steroids
 

Último

Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...confluent
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Angel Borroy López
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odishasmiwainfosol
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEEVICTOR MAESTRE RAMIREZ
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmSujith Sukumaran
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样umasea
 
cpct NetworkING BASICS AND NETWORK TOOL.ppt
cpct NetworkING BASICS AND NETWORK TOOL.pptcpct NetworkING BASICS AND NETWORK TOOL.ppt
cpct NetworkING BASICS AND NETWORK TOOL.pptrcbcrtm
 
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdfExploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdfkalichargn70th171
 
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsSensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsChristian Birchler
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Natan Silnitsky
 
VK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web DevelopmentVK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web Developmentvyaparkranti
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfMarharyta Nedzelska
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Andreas Granig
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作qr0udbr0
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaHanief Utama
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Cizo Technology Services
 

Último (20)

Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalm
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
 
cpct NetworkING BASICS AND NETWORK TOOL.ppt
cpct NetworkING BASICS AND NETWORK TOOL.pptcpct NetworkING BASICS AND NETWORK TOOL.ppt
cpct NetworkING BASICS AND NETWORK TOOL.ppt
 
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdfExploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
 
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsSensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
 
VK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web DevelopmentVK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web Development
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdf
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief Utama
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 
Odoo Development Company in India | Devintelle Consulting Service
Odoo Development Company in India | Devintelle Consulting ServiceOdoo Development Company in India | Devintelle Consulting Service
Odoo Development Company in India | Devintelle Consulting Service
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
 

Want to write a book in Jupyter - here's how

  • 1. Want to write a book in Jupyter - here’s how Dr Jim Arlow, Clear View Training Limited www.clearviewtraining.com 1
  • 2. Introduction • In this presentation, we will demonstrate how to use Jupyter notebooks to deliver interactive long form text such as books • We will quickly take a look at some common options for creating interactive text, and then go to develop a set of requirements and tools for using Jupyter as an authoring platform for books 2
  • 3. About the author • Jim Arlow is an independent consultant, trainer and author working in OO analysis and design, UML modelling, BPMN, Metadata Management, Model Driven Architecture (MDA), requirements engineering and software engineering process design and implementation • He is author of the best selling, “UML 2 and the Unified Process”, and you can find a list of all of his books here: www.clearviewtraining.com • Contact: • www.clearviewtraining.com • https://www.linkedin.com/in/jimarlow 3 Check out my latest book! http://bit.ly/SecretsOfAnalysis
  • 4. Options for writing long- form interactive texts • It is quite surprising how few platforms there are that are easy to use for creating interactive long-form texts! • We have direct experience with: • Apple iBooks Author • Mathematica • Jupyter • Of course, you can always use HTML, but that is a complex option… • Frameworks and libraries for interactivity • Hosting mechanisms and distribution • Etc. etc. 4
  • 5. Apple iBooks Author • Creates truly beautiful interactive books! • Simple and fun to use! • Built in interactive widgets are limited (e.g. quizzes, interactive graphics etc.) • Hard to create custom interactive widgets using HTML5 • Can’t include live code • Limited distribution - does anyone actually use the Apple Books Store? http://bit.ly/IntroductionToBPMN2 5 Check it out!
  • 6. Mathematica • Insanely powerful and elegant! • Easy to use authoring environment with full mathematical notation and live code • Very rich interactivity via the Manipulate command and more • Licensing to sell books is prohibitively costly for small authors/publishers • Distribution via Mathematica viewer (free) is to be phased out and replaced by deployment on a website (costly) - no sensible option left for free books http://bit.ly/2DBoBnC 6
  • 7. Jupyter • Many of the advantages of Mathematica but with open source licensing • Live Python code (the default) has more traction than live Mathematica code • Good support for interactive widgets via interact functions • Many options for deployment • Many options for live code • More popular than Mathematica?? • How do you package and sell Jupyter Notebooks? 7
  • 8. What is Jupyter? • From the Jupyter website http://jupyter.org/index.html: • “The Jupyter Notebook is an open-source web application that allows you to create and share documents that contain: • Live code • Equations • Visualisations • Narrative text • Interactive widgets • Uses include: data cleaning and transformation, numerical simulation, statistical modelling, data visualisation, machine learning, and much more”. 8
  • 9. How Jupyter works • Server runs notebook code (usually Python) and serves up static HTML and dynamic interactive widgets to the client web browser Interactive Computing Protocol Jupyter Notebook Server NB1 Code Text Data Widgets NB2 Code Text Data Widgets NB3 Code Text Data Widgets Browser 9
  • 10. Jupyter for books • Books shall be delivered as a sequence of Jupyter notebooks, one per chapter • Each chapter shall build on the previous one (so we need to reuse code between chapters) • A reusable code base shall be extracted from book • Each chapter shall have a table of contents (TOC) • Each section shall have a link back to the TOC • The whole book shall have a table of contents 10
  • 11. Jupyter book structure • A book comprises several chapters with one Jupyter notebook per chapter e.g. C1.ipynb • Notebooks allow headings and sub headings • Each chapter builds on the previous one and needs to reuse its code • Export of code is done using the nbconvert utility (see later) C1.ipynb C1.py C2.ipynb Convert import C3.ipynb C3.py C4.ipynb Convert import C2.py Convert import nbconvert Reusable code 11 Jupyter Notebooks Convert C4.py Python import
  • 12. Two types of code… 1. Reusable code must be factored out for use in subsequent chapters and elsewhere: • Python classes • Functions • Global variables etc. 2. Non-reusable (demo) code that needs to be constrained to execution within a notebook: • Interactive demonstration code • Static output such as tables 12
  • 13. Reusable and non-reusable code Reusable function Non-reusable (demo) code Interactive widgets Need to remove all non- reusable code 13
  • 14. Identifying demo code • This is code that should not be reused outside of the notebook! • By convention: begin each demo code cell with #Demo and end it with #Demo • By metadata: add the DEMO tag to each demo code cell so that it can be identified and removed later • Open the View:Cell toolbar:Tags menu to see the tags associated with each cell We will use DEMO to filter out this cell using nbconvert 14
  • 15. Extracting the code… • Filter the notebooks using the nbconvert utility to discard: • Markup, graphics, cell inputs, outputs and prompts • Demo code - remove all cells with the tag DEMO with the option: 
 --TagRemovePreprocessor.remove_cell_tags={"DEMO"} !jupyter nbconvert --to python --TemplateExporter.exclude_input_prompt=True --TemplateExporter.exclude_output_prompt=True --TemplateExporter.exclude_output=True --TemplateExporter.exclude_markdown=True --TagRemovePreprocessor.remove_cell_tags={"DEMO"} Introduction Pitch MusicalSetTheory MusicalSetTheory2 Scales Reusable Python Code Reusable Python Code Reusable Python Code Scales.py Reusable Code nbconvert (executed in a Jupyter cell) 15
  • 16. What we have achieved… • Books shall be delivered as a sequence of Jupyter notebooks, one per chapter • Each chapter shall build on the previous one (so we need to reuse code between chapters) • A reusable code base shall be extracted from book • Each chapter needs a table of contents (TOC) and navigation from each section back to the TOC • The book as a whole needs a table of contents 16
  • 17. Chapter TOC • Jupyter notebooks are missing an important feature - the ability to automatically generate a table of contents, so we will handcraft a solution! • Mark up TOC entries by convention: • The first line in a markdown cell shall be a candidate TOC entry • A TOC entry line shall begin with one or more # • A TOC entry line shall end with a single # • Note: We could have used tags again, but this markup convention is much easier! • Extract marked up TOC entries and generate TOC in notebook 17
  • 18. Example TOC entry Ends with #Begins with # First line 18
  • 19. Extracting the TOC entries • Jupyter notebooks are JSON documents that have a hierarchical structure • This means that it is relatively easy to parse them to extract information JSON Notebook Data cell source cell If first line of source looks like “# …#” “## …#” etc. Add to TOC Notebook with TOC 19
  • 20. Load notebook as JSON Find TOC entry convention Generate markup hyperlinks for an indented list of headings Embed TOC in current notebook HTML anchor TOC TocTools.py Include this module in your notebooks 20
  • 21. Call function in Jupyter notebook to embed TOC Call the function on the current notebook file to generate the TOC The generated TOC has an anchor so you can link back to it This file is Pitch.ipynb - make sure you call on the right file! 21
  • 22. Book TOC • Ideally, the book TOC should contain a concatenation of all of the chapter TOCs with active hyperlinks • For now, we will compromise by limiting the book TOC to a list of chapters because it is easy to hyperlink to a chapter to see its contents - we may revisit this decision later! • The problem is that a normal hyperlink opens a new instance of the target notebook: 22 Pitch.ipynb Pitch.ipynb Pitch.ipynb Transposition Open a new instance
  • 23. Generating the book TOC • Just use standard Jupyter hyperlinks that you can generate from a list of chapters: 23
  • 24. Summary • Books shall be delivered as a sequence of Jupyter notebooks, one per chapter • Each chapter shall build on the previous one (so we need to reuse code between chapters) • A reusable code base shall be extracted from book • Each chapter shall have a table of contents (TOC) • Each section shall have a link back to the TOC • The whole book shall have a table of contents • Conclusion: Jupyter is an excellent platform for the delivery of interactive long-form content! 24