July 15, 2020 ☼ Python ☼ Guides ☼ Programming
Python notebooks (e.g., Jupyter Notebooks) are a staple of scientific computing and are increasingly an important pedagogical tool. The key reason why Python notebooks are a powerful education medium is that they combine running and editing raw Python code alongside full-textual comments, enabling educators to include pedagogical comments within a fully functional Python environment. However, while Python notebooks are a great medium, there is a small activation barrier before students could traditionally get started: downloading and installing Jupyter Notebooks (often through the Anaconda distribution). While this is usually not an obstacle for students versed in programming, it may present an unnecessary hurdle to get students started or for small illustrative examples. Instead, you can host and serve these notebooks using online services to facilitate easy access to the fully interactive environment. Let’s get started!
Instead of distributing Python notebooks to students and asking them to install Jupyter Notebooks locally, you can host and serve them online. This workflow facilitates a one-click access to an interactive copy that they can edit (temporary changes that don’t affect the source file) and download the files for further modifications, reducing the friction for students to start leveraging the interactive nature of the notebook environment. There are two primary methods for hosting and serving your notebooks online: Google Colab and Binder. In this guide, I’ll introduce a workflow to utilize these services for your educational content. For both services, I recommend hosting the files online in a git repository, such as through GitHub or GitLab. If you are unfamiliar with GitHub, you should walk through one of the many great online tutorials (such as this one) before working through the rest of this guide.
Binder is an online service that transforms a Git repository into a cloud-hosted JuypterHub (server-based Jupyter Notebooks application) instance. Using this service provides a native Jupyer Notebooks interface with interactive content accessible through a single click through a URL.
requirements.txt
(equivalent to a pip install
setup, see documentation) or an environment.yml
(equivalent to an Anaconda setup, see documentation).Example of an environment.yml from the repository for this blog.
Fill in the repository, branch, and path to the notebook (optional) on mybinder.org.
Example of completed Binder setup.
Access the instance using the URL provided on the page. The landing page (which is what students will first see) will show the current status until it is ready.
Example of Binder landing page.
https://mybinder.org/v2/gh/{username}/{repository}/{branch}/{path-to-notebook}
Using Binder comes with a set of advantages and disadvantages that you should be aware of:
Advantages
Disadvantages
Google Colab is a browser-based Python notebook programming environment provided by Google. While the functionality is similar to Binder and the traditional Jupyter Notebook, Google Colab utilizes a unique user interface. This service integrates with Google Drive and can also serve Python notebooks hosted elsewhere. I’ll introduce two ways to use Google Colab: 1) Hosting files directly in Google Drive, 2) Hosting files on GitHub.
Prior to utilizing Google Colab, students will need to install the plugin for their Google Drive account. Installation is an easy process:
Hosting your Python notebooks on Google Drive to use with Google Colab is similar to managing shared Google Docs, Sheets, or Slides. While this method seems less complicated than other methods, there are additional steps surrounding sharing and editing settings that may lead to problems.
To get around potential sharing permission problems inherent in hosting notebooks directly on Google Drive, you can host the notebooks on an external source, such as GitHub, and serve them through the Google Colab interface. The original integration documentation can be found here. Unlike hosting the files directly in Google Drive, there are no risks of editing the source.
https://colab.research.google.com/github/{GitHub Account}/{repository}/blob/{branch}/{pathname}
Example of generating the Colab URL using the Chrome Extension
Share the final link with students to give them access
Just like the Binder workflow, utilizing Google Colab comes with advantages and disadvantages.
Advantages
Disadvantages
Python notebooks are useful pedagogical tools for teaching programming or providing students interactive environments to explore mathematical models. However, depending on the nature of the content and the experience level of your students, requiring them to install the necessary components to work with these files locally on their computer may not be the best option. Using Binder or Google Colab lets you host and serve Python notebooks entirely online without requiring a local installation. While setting up this workflow may require more work than distributing the raw files directly, I believe this dramatically improves the accessibility for non-programmers or quick, interactive demonstrations. I hope you have found this guide helpful for setting up your online workflow!