Python Friday #163: Share Your Jupyter Notebooks

After we created our analysis, it is time to share our Jupyter notebooks. Let us look at the options we have.

This post is part of my journey to learn Python. You can find the other parts of this series here. You find the code for this post in my PythonFriday repository on GitHub.

 

Share the *.ipynb file

We can save our Jupyter Notebook to a *.ipynb file, either by using the File / Download menu entry or by copying the file directly form the file system:

The menu File / Download gets you your notebook

You can share this file your colleagues and they can use the menu entry File / Open from Path… to open the notebook in their JupyterLab instance:

The menu File / Open from Path… to run your notebook

Various other tools like VS Code or PyCharm allow you to open a *.ipynb file as well and offer a similar experience to work with the notebook as you know from JupyterLab.

 

Share via GitHub

If you share your notebook as a *.ipynb file via GitHub, you get a preview of the notebook directly in the web view:

GitHub runs your Notebook and shows you the result in the web view

If your colleagues only need a read-only view, then the GitHub preview may be enough. And if you work with others on a notebook, Git (and GitHub) makes it much simpler to share the changes.

 

Export to various formats

In the JupyterLab application is a menu item File / Save and Export Notebook As… with these formats:

You can export your notebook to PDF, HTML, Markdown and many more formats

The Markdown and HTML format work out of the box with no additional packages. The other formats require Pandoc and various other packages to work. I suggest you only install what you really need. Otherwise you fill your system with many packages that will be no use to you.

A little tip for Pandoc: Pandoc is an executable that will only be available in your console and JupyterLab after you reinitialised the console. Therefore, you best start a new console to run JupyterLab with your freshly installed Pandoc.

 

Export to Python (Jupyter Notebook only)

If you run the old Jupyter Notebook application, you get the option to download your notebook as a Python file in the menu File / Download as / Python (.py):

The old application offers a menu File / Download as / Python (.py)

This merges all your cells into a single Python file and comments out the Markdown cells:

While the usefulness of this export format is debatable, I think it is good to know that it exists.

 

Online services

To complete the list I have a few words on online services. There are numerous offerings that allow you to host your notebooks online. Depending on the business model of those platforms, you may need to pay more or less to get an easy way to share your work. So far, I do not have enough experience to make a suggestion on where to host your notebooks. If you can fill the blanks, please leave a comment with your suggestions.

 

Next

Now that we can share our Jupyter Notebooks, we have everything together to do some interesting work. Starting next week, we look at Matplotlib and how we can turn boring data into useful visualisations.

1 thought on “Python Friday #163: Share Your Jupyter Notebooks”

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.