I tend to preserve and post online all the work I do for later reference and sharing. Jupyter Notebooks are a bit more complex than standard source code because they are natively in a format (JSON) that needs to be rendered to be readable.
Most of the times you want to share a static copy of your “executed” notebook which contains all the generated plots and outputs.
Render larger Notebooks via nbviewer
The Github rendering engine is not the most reliable: it fails for larger notebooks, it doesn’t work on mobile and it doesn’t support some JavaScript based libraries, like altair
.
Then after having uploaded your Notebook to gist
, you can go to https://nbviewer.jupyter.org/, paste the full link to your gist
and share the nbviewer
rendering instead.
Save clean Notebooks in Github repositories
I also recommend to save a copy of notebooks without any outputs (either doing “Clear all outputs” from the interface or using nbstripout
) into a related Github repository, this makes it easier to reference it later on. However don’t save executed notebooks inside Github repositories, they are too large and cause ugly diff
between versions (also use nbdime
to help manage notebooks inside repos).
Make notebooks executable in the browser
Once you have notebooks in a repository, you can also plug them into https://mybinder.org/ to allow people to spin a Virtual Machine on Google Cloud automatically and for free and execute them in their browser. You can also provide a environment.yml
file to setup the requirements.
See for example the healpy
tutorial gist, which can be executed on Binder clicking on the following Icon: