Sharing Jupyter Notebooks with Binder

One of the great developments in data science is undoubtedly the ‘Notebook’ approach to working through data problems. Of these, the Jupyter Notebook is the best known, although others exist also such as Zeppelin. Notebooks allow you to create a single reference document holding data, markdown text, code and graphical outputs – all in one place. Notebooks can therefore be a very instructive self-contained means to share your work with others. However, the act of sharing can be complex. Firstly, the current practice is to place your code on a sharing and collaboration tool, such as Github as a ‘repo’ (repository). Then, in order to experiment with your solution, the person receiving the code has to be able to run the notebook, and to do this they also need to be able to recreate the environment you used – with all the libraries and functionality preserved intact.

A fantastic development to help with this is ‘Binder‘. Binder allows you to turn a Git repo into a collection of interactive online and shareable notebooks. So if you have a repository with Jupyter notebooks, then with Binder, your users can open your notebooks in an executable environment, making your code immediately reproducible by anyone, anywhere.

To demonstrate this, we constructed a short Jupyter Notebook that outputs a Fibonacci sequence. We used the Digital Environment Github to hold our repo.

To use Binder to build a shareable interactive and online version of the notebook, we then visited the Binder website – https://mybinder.org

Next, we entered the repository information. To do this we provided the URL of the GitHub repository that contains the Jupyter notebooks. By naming the notebook file explicitly, the notebook will be opened directly in your browser after it is built.

Binder configuration
Binder configuration

Binder works by build a Docker image of the repository. Binder searches for a dependency file, such as requirements.txt or environment.yml, in the repository’s root directory. The dependency files will be used to build a Docker image. If an image has already been built for the given repository, it will not be rebuilt. If a new commit has been made, the image will automatically be rebuilt.

It is then simple to copy off a URL address to the Binder resource. The URL can then easily be linked from your website. The example URL for our notebook is

https://mybinder.org/v2/gh/SPFDigiEnv/Fibonacci/master?filepath=Fibonacci.ipynb


All that is left is to click on the link to interact with your notebook in a live environment! A JupyterHub server will host your repository’s contents. Binder offers a reusable link and badge to your live repository that you can then easily share with others.

Binder works with Python, Julia and R notebooks.

The resulting Jupyter Notebook running in Binder
The resulting Jupyter Notebook running in Binder