SlideShare a Scribd company logo
1 of 24
Download to read 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

More Related Content

What's hot

Kn dat muc tieu va lap kh 26.7
Kn dat muc tieu va lap kh 26.7Kn dat muc tieu va lap kh 26.7
Kn dat muc tieu va lap kh 26.7tn4417
 
6_XLA6_Nen anh.pdf
6_XLA6_Nen anh.pdf6_XLA6_Nen anh.pdf
6_XLA6_Nen anh.pdfTrnXun28
 
Hoàn thiện các giải pháp quản trị nguồn nhân lực của công ty trách nhiệm hữu ...
Hoàn thiện các giải pháp quản trị nguồn nhân lực của công ty trách nhiệm hữu ...Hoàn thiện các giải pháp quản trị nguồn nhân lực của công ty trách nhiệm hữu ...
Hoàn thiện các giải pháp quản trị nguồn nhân lực của công ty trách nhiệm hữu ...NOT
 
LUẬN VĂN THẠC SĨ: ĐÀO TẠO NGUỒN NHÂN LỰC TẠI CÔNG TY CỔ PHẨN BIA
LUẬN VĂN THẠC SĨ: ĐÀO TẠO NGUỒN NHÂN LỰC TẠI CÔNG TY CỔ PHẨN BIALUẬN VĂN THẠC SĨ: ĐÀO TẠO NGUỒN NHÂN LỰC TẠI CÔNG TY CỔ PHẨN BIA
LUẬN VĂN THẠC SĨ: ĐÀO TẠO NGUỒN NHÂN LỰC TẠI CÔNG TY CỔ PHẨN BIAOnTimeVitThu
 
gGiaotrinhlaprapcaidatmaytinhnew2013 140119205441-phpapp01
gGiaotrinhlaprapcaidatmaytinhnew2013 140119205441-phpapp01gGiaotrinhlaprapcaidatmaytinhnew2013 140119205441-phpapp01
gGiaotrinhlaprapcaidatmaytinhnew2013 140119205441-phpapp01Anh Lê Công
 
ĐIỀU KHIỂN HỆ ĐA TÁC TỬ.pdf
ĐIỀU KHIỂN HỆ ĐA TÁC TỬ.pdfĐIỀU KHIỂN HỆ ĐA TÁC TỬ.pdf
ĐIỀU KHIỂN HỆ ĐA TÁC TỬ.pdfMan_Ebook
 
Bai giang th._hoa_sinh_moi_nhat
Bai giang th._hoa_sinh_moi_nhatBai giang th._hoa_sinh_moi_nhat
Bai giang th._hoa_sinh_moi_nhatngocthuan2n
 
Báo cáo tốt nghiệp Nâng cao hiệu quả hoạt động cho vay của khách hàng cá nhân...
Báo cáo tốt nghiệp Nâng cao hiệu quả hoạt động cho vay của khách hàng cá nhân...Báo cáo tốt nghiệp Nâng cao hiệu quả hoạt động cho vay của khách hàng cá nhân...
Báo cáo tốt nghiệp Nâng cao hiệu quả hoạt động cho vay của khách hàng cá nhân...https://www.facebook.com/garmentspace
 
Nâng cao chất lượng tín dụng đối với khách hàng cá nhân tại Ngân hàng Thương ...
Nâng cao chất lượng tín dụng đối với khách hàng cá nhân tại Ngân hàng Thương ...Nâng cao chất lượng tín dụng đối với khách hàng cá nhân tại Ngân hàng Thương ...
Nâng cao chất lượng tín dụng đối với khách hàng cá nhân tại Ngân hàng Thương ...Dịch vụ viết bài trọn gói ZALO: 0936 885 877
 
Báo cáo đồ án máy cắt cuốn bánh dâu
Báo cáo đồ án máy cắt cuốn bánh dâu   Báo cáo đồ án máy cắt cuốn bánh dâu
Báo cáo đồ án máy cắt cuốn bánh dâu TrungVo73
 
Metasploit 24-03-2014
Metasploit 24-03-2014Metasploit 24-03-2014
Metasploit 24-03-2014renlue
 
Công tác đào tạo và phát triển nguồn nhân lực công ty cổ phần thương mại vận ...
Công tác đào tạo và phát triển nguồn nhân lực công ty cổ phần thương mại vận ...Công tác đào tạo và phát triển nguồn nhân lực công ty cổ phần thương mại vận ...
Công tác đào tạo và phát triển nguồn nhân lực công ty cổ phần thương mại vận ...Thư viện Tài liệu mẫu
 
QUẢN TRỊ RỦI RO TÍN DỤNG TẠI NGÂN HÀNG TMCP QUÂN ĐỘI – CHI NHÁNH SỞ GIA...
QUẢN TRỊ RỦI RO TÍN DỤNG TẠI NGÂN HÀNG    TMCP QUÂN ĐỘI –    CHI NHÁNH SỞ GIA...QUẢN TRỊ RỦI RO TÍN DỤNG TẠI NGÂN HÀNG    TMCP QUÂN ĐỘI –    CHI NHÁNH SỞ GIA...
QUẢN TRỊ RỦI RO TÍN DỤNG TẠI NGÂN HÀNG TMCP QUÂN ĐỘI – CHI NHÁNH SỞ GIA...lamluanvan.net Viết thuê luận văn
 
Đề tài: Ứng dụng xử lý ảnh nhận dạng cử chỉ bàn tay điều khiển ro...
Đề tài: Ứng dụng xử lý ảnh nhận dạng cử chỉ bàn tay điều khiển ro...Đề tài: Ứng dụng xử lý ảnh nhận dạng cử chỉ bàn tay điều khiển ro...
Đề tài: Ứng dụng xử lý ảnh nhận dạng cử chỉ bàn tay điều khiển ro...Viết thuê trọn gói ZALO 0934573149
 

What's hot (20)

Hoàn thiện công tác chăm sóc khách hàng tại ngân hàng quân đội.docx
Hoàn thiện công tác chăm sóc khách hàng tại ngân hàng quân đội.docxHoàn thiện công tác chăm sóc khách hàng tại ngân hàng quân đội.docx
Hoàn thiện công tác chăm sóc khách hàng tại ngân hàng quân đội.docx
 
Kn dat muc tieu va lap kh 26.7
Kn dat muc tieu va lap kh 26.7Kn dat muc tieu va lap kh 26.7
Kn dat muc tieu va lap kh 26.7
 
6_XLA6_Nen anh.pdf
6_XLA6_Nen anh.pdf6_XLA6_Nen anh.pdf
6_XLA6_Nen anh.pdf
 
Hoàn thiện các giải pháp quản trị nguồn nhân lực của công ty trách nhiệm hữu ...
Hoàn thiện các giải pháp quản trị nguồn nhân lực của công ty trách nhiệm hữu ...Hoàn thiện các giải pháp quản trị nguồn nhân lực của công ty trách nhiệm hữu ...
Hoàn thiện các giải pháp quản trị nguồn nhân lực của công ty trách nhiệm hữu ...
 
LUẬN VĂN THẠC SĨ: ĐÀO TẠO NGUỒN NHÂN LỰC TẠI CÔNG TY CỔ PHẨN BIA
LUẬN VĂN THẠC SĨ: ĐÀO TẠO NGUỒN NHÂN LỰC TẠI CÔNG TY CỔ PHẨN BIALUẬN VĂN THẠC SĨ: ĐÀO TẠO NGUỒN NHÂN LỰC TẠI CÔNG TY CỔ PHẨN BIA
LUẬN VĂN THẠC SĨ: ĐÀO TẠO NGUỒN NHÂN LỰC TẠI CÔNG TY CỔ PHẨN BIA
 
Luận văn: Kiểm thử tự động tương tác giao diện người dùng, 9đ
Luận văn: Kiểm thử tự động tương tác giao diện người dùng, 9đLuận văn: Kiểm thử tự động tương tác giao diện người dùng, 9đ
Luận văn: Kiểm thử tự động tương tác giao diện người dùng, 9đ
 
gGiaotrinhlaprapcaidatmaytinhnew2013 140119205441-phpapp01
gGiaotrinhlaprapcaidatmaytinhnew2013 140119205441-phpapp01gGiaotrinhlaprapcaidatmaytinhnew2013 140119205441-phpapp01
gGiaotrinhlaprapcaidatmaytinhnew2013 140119205441-phpapp01
 
Luận án: Hiệu quả hoạt động kinh doanh của các ngân hàng thương mại cổ phần V...
Luận án: Hiệu quả hoạt động kinh doanh của các ngân hàng thương mại cổ phần V...Luận án: Hiệu quả hoạt động kinh doanh của các ngân hàng thương mại cổ phần V...
Luận án: Hiệu quả hoạt động kinh doanh của các ngân hàng thương mại cổ phần V...
 
ĐIỀU KHIỂN HỆ ĐA TÁC TỬ.pdf
ĐIỀU KHIỂN HỆ ĐA TÁC TỬ.pdfĐIỀU KHIỂN HỆ ĐA TÁC TỬ.pdf
ĐIỀU KHIỂN HỆ ĐA TÁC TỬ.pdf
 
Bai giang th._hoa_sinh_moi_nhat
Bai giang th._hoa_sinh_moi_nhatBai giang th._hoa_sinh_moi_nhat
Bai giang th._hoa_sinh_moi_nhat
 
Báo cáo tốt nghiệp Nâng cao hiệu quả hoạt động cho vay của khách hàng cá nhân...
Báo cáo tốt nghiệp Nâng cao hiệu quả hoạt động cho vay của khách hàng cá nhân...Báo cáo tốt nghiệp Nâng cao hiệu quả hoạt động cho vay của khách hàng cá nhân...
Báo cáo tốt nghiệp Nâng cao hiệu quả hoạt động cho vay của khách hàng cá nhân...
 
Luận văn: Nhận dạng cảm xúc khuôn mặt người, HAY, 9đ
Luận văn: Nhận dạng cảm xúc khuôn mặt người, HAY, 9đLuận văn: Nhận dạng cảm xúc khuôn mặt người, HAY, 9đ
Luận văn: Nhận dạng cảm xúc khuôn mặt người, HAY, 9đ
 
Nâng cao chất lượng tín dụng đối với khách hàng cá nhân tại Ngân hàng Thương ...
Nâng cao chất lượng tín dụng đối với khách hàng cá nhân tại Ngân hàng Thương ...Nâng cao chất lượng tín dụng đối với khách hàng cá nhân tại Ngân hàng Thương ...
Nâng cao chất lượng tín dụng đối với khách hàng cá nhân tại Ngân hàng Thương ...
 
Báo cáo đồ án máy cắt cuốn bánh dâu
Báo cáo đồ án máy cắt cuốn bánh dâu   Báo cáo đồ án máy cắt cuốn bánh dâu
Báo cáo đồ án máy cắt cuốn bánh dâu
 
Luận văn: Quản trị rủi ro trong cho vay tiêu dùng tại Ngân hàng BIDV
Luận văn: Quản trị rủi ro trong cho vay tiêu dùng tại Ngân hàng BIDVLuận văn: Quản trị rủi ro trong cho vay tiêu dùng tại Ngân hàng BIDV
Luận văn: Quản trị rủi ro trong cho vay tiêu dùng tại Ngân hàng BIDV
 
Metasploit 24-03-2014
Metasploit 24-03-2014Metasploit 24-03-2014
Metasploit 24-03-2014
 
Công tác đào tạo và phát triển nguồn nhân lực công ty cổ phần thương mại vận ...
Công tác đào tạo và phát triển nguồn nhân lực công ty cổ phần thương mại vận ...Công tác đào tạo và phát triển nguồn nhân lực công ty cổ phần thương mại vận ...
Công tác đào tạo và phát triển nguồn nhân lực công ty cổ phần thương mại vận ...
 
Báo cáo thực tập hoàn thiện công tác đào tạo, phát triển nguồn nhân lực tại c...
Báo cáo thực tập hoàn thiện công tác đào tạo, phát triển nguồn nhân lực tại c...Báo cáo thực tập hoàn thiện công tác đào tạo, phát triển nguồn nhân lực tại c...
Báo cáo thực tập hoàn thiện công tác đào tạo, phát triển nguồn nhân lực tại c...
 
QUẢN TRỊ RỦI RO TÍN DỤNG TẠI NGÂN HÀNG TMCP QUÂN ĐỘI – CHI NHÁNH SỞ GIA...
QUẢN TRỊ RỦI RO TÍN DỤNG TẠI NGÂN HÀNG    TMCP QUÂN ĐỘI –    CHI NHÁNH SỞ GIA...QUẢN TRỊ RỦI RO TÍN DỤNG TẠI NGÂN HÀNG    TMCP QUÂN ĐỘI –    CHI NHÁNH SỞ GIA...
QUẢN TRỊ RỦI RO TÍN DỤNG TẠI NGÂN HÀNG TMCP QUÂN ĐỘI – CHI NHÁNH SỞ GIA...
 
Đề tài: Ứng dụng xử lý ảnh nhận dạng cử chỉ bàn tay điều khiển ro...
Đề tài: Ứng dụng xử lý ảnh nhận dạng cử chỉ bàn tay điều khiển ro...Đề tài: Ứng dụng xử lý ảnh nhận dạng cử chỉ bàn tay điều khiển ro...
Đề tài: Ứng dụng xử lý ảnh nhận dạng cử chỉ bàn tay điều khiển ro...
 

Similar to 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
 

Similar to 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
 

Recently uploaded

Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
Active Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfActive Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfCionsystems
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionSolGuruz
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataBradBedford3
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerThousandEyes
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number SystemsJheuzeDellosa
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfkalichargn70th171
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about usDynamic Netsoft
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsAndolasoft Inc
 

Recently uploaded (20)

Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
Active Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfActive Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdf
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number Systems
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about us
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 

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