|
| 1 | +# Sharing notebooks |
| 2 | + |
| 3 | +:::{objectives} |
| 4 | +- Know about good practices for notebooks to make them reusable |
| 5 | +- Have a recipe to share a dynamic and reproducible visualization pipeline |
| 6 | +::: |
| 7 | + |
| 8 | +[this lesson is adapted after <https://coderefinery.github.io/jupyter/sharing/>] |
| 9 | + |
| 10 | + |
| 11 | +## Document dependencies |
| 12 | + |
| 13 | +- If you import libraries into your notebook, note down their versions. |
| 14 | + Document the dependencies as discussed in section {doc}`../dependencies`. |
| 15 | + |
| 16 | +- Place either `environment.yml` or `requirements.txt` in the same folder as |
| 17 | + the notebook(s). |
| 18 | + |
| 19 | +- If you publish the notebook as part of a publication, it is probably a good |
| 20 | + idea to **pin the versions** of the libraries you use. |
| 21 | + |
| 22 | +- This is not only useful for people who will try to rerun this in future, it |
| 23 | + is also understood by some tools (e.g. [Binder](https://mybinder.org/)) which we |
| 24 | + will see later. |
| 25 | + |
| 26 | + |
| 27 | +## Different ways to share a notebook |
| 28 | + |
| 29 | +We need to learn how to share notebooks. At the minimum we need |
| 30 | +to share them with our future selves (backup and reproducibility). |
| 31 | + |
| 32 | +- You can enter a URL, GitHub repo or username, or GIST ID in [nbviewer](https://nbviewer.jupyter.org/) and view a rendered Jupyter notebook |
| 33 | +- Read the Docs can render Jupyter Notebooks via the [nbsphinx package](https://nbsphinx.readthedocs.io/) |
| 34 | +- [Binder](https://mybinder.org/) creates live notebooks based on a GitHub repository |
| 35 | +- [EGI Notebooks](https://notebooks.egi.eu) (see also <https://egi-notebooks.readthedocs.io>) |
| 36 | +- [JupyterLab](https://github.com/jupyterlab/jupyterlab) supports sharing and collaborative editing of notebooks via Google Drive. Recently |
| 37 | + it also added support for [Shared editing with collaborative notebook model](https://github.com/jupyterlab/jupyterlab/pull/10118). |
| 38 | +- [JupyterLite](https://jupyterlite.readthedocs.io/en/latest/) creates a Jupyterlab environment in the browser and can be hosted as a GitHub page. |
| 39 | +- [Notedown](https://github.com/aaren/notedown), [Jupinx](https://github.com/QuantEcon/sphinxcontrib-jupyter) and [DocOnce](https://github.com/hplgit/doconce) can take Markdown or Sphinx files and generate Jupyter Notebooks |
| 40 | +- [Voilà](https://voila.readthedocs.io/en/stable/) allows you to convert a Jupyter Notebook into an interactive dashboard |
| 41 | +- The `jupyter nbconvert` tool can convert a (`.ipynb`) notebook file to: |
| 42 | + - python code (`.py` file) |
| 43 | + - an HTML file |
| 44 | + - a LaTeX file |
| 45 | + - a PDF file |
| 46 | + - a slide-show in the browser |
| 47 | + |
| 48 | + |
| 49 | +The following platforms can be used free of charge but have **paid subscriptions** for |
| 50 | +faster access to cloud resources: |
| 51 | +- [CoCalc](https://cocalc.com/) (formerly SageMathCloud) allows collaborative editing of notebooks in the cloud |
| 52 | +- [Google Colab](https://colab.research.google.com/) lets you work on notebooks in the cloud, and you can [read and write to notebook files on Drive](https://colab.research.google.com/notebooks/io.ipynb) |
| 53 | +- [Microsoft Azure Notebooks](https://notebooks.azure.com/) also offers free notebooks in the cloud |
| 54 | +- [Deepnote](https://deepnote.com/) allows real-time collaboration |
| 55 | + |
| 56 | + |
| 57 | +## Sharing dynamic notebooks using [Binder](https://mybinder.org/) |
| 58 | + |
| 59 | +::::{challenge} Exercise/demo: Making your notebooks reproducible by anyone (15 min) |
| 60 | +Instructor demonstrates this: |
| 61 | +- First we look at the statically rendered version of the [example |
| 62 | + notebook](https://github.com/workshop-material/classification-task/blob/main/example.ipynb) |
| 63 | + on GitHub and also [nbviewer](https://nbviewer.jupyter.org/). |
| 64 | +- Visit [https://mybinder.org](https://mybinder.org): |
| 65 | + :::{figure} binder.jpg |
| 66 | + :alt: Screenshot from mybinder.org user interface |
| 67 | + ::: |
| 68 | +- Check that your notebook repository now has a "launch binder" |
| 69 | + badge in your `README.md` file on GitHub. |
| 70 | +- Try clicking the button and see how your repository is launched |
| 71 | + on Binder (can take a minute or two). Your notebooks can now be |
| 72 | + explored and executed in the cloud. |
| 73 | +- Enjoy being fully reproducible! |
| 74 | +:::: |
| 75 | + |
| 76 | + |
| 77 | +## How to get a digital object identifier (DOI) |
| 78 | + |
| 79 | +- [Zenodo](https://zenodo.org/) is a great service to get a |
| 80 | + [DOI](https://en.wikipedia.org/wiki/Digital_object_identifier) for a notebook |
| 81 | + (but **first practice** with the [Zenodo sandbox](https://sandbox.zenodo.org/)). |
| 82 | +- [Binder](https://mybinder.org/) can also run notebooks from Zenodo. |
| 83 | +- In the supporting information of your paper you can refer to its DOI. |
0 commit comments