Creating a Jupyter Notebook Extension — Part 1

I’m building a new GUI for Pandas aptly called “Pandamonium” as a Jupyter Notebook Extension. I’ve not built a Jupyter Notebook extension before and I’ve spent this last weekend learning all about the extension eco-system. I’m going to share my learnings with a series of blog posts — a great way to get me to blog again in a pretty hectic 2020. This first post covers creating a simple extension that you can modify and see the changes reflected in a Notebook. I did not find much useful documentation (especially when using conda) so hopefully, this blog post will be useful to anybody starting out with Jupyter Notebook extensions.

Step 1: Create and activate a conda virtual environment

Step 2: Install jupyter_contrib_nbextensions

Step 3: Find the location of the nbextensions folder

Step 4: Explore some existing extensions

$ jupyter notebook

Enabling Jupyter Notebook Extensions

In /Users/username/anaconda3/envs/jupyterexperiments/lib/python3.7/site-packages/jupyter_contrib_nbextensions/nbextensions you will find a folder for each of the extensions.

Folders for Installed Jupyter Extensions

Explore the code of any extension. You see that most extensions only contain .yaml, main.js and readme.md file. Some more complex extensions also contain python code.

The basic structure of a Jupyter Notebook Extension

Step 5: Create your first extension — Planet Jupyter

Create a new folder called planet_jupyter
$ mkdir planet_jupyter
$ cd planet_jupyter

Add a readme.md file and include some info on the extension.

Add a description.yaml file. Set Name to “Planet Jupyter” and Main to the name of the javascript file.

The description.yaml file

Next add a main.js file. The javascript in this file must follow the AMD module syntax. The code below adds a button to the Toolbar and provides code to run when the button is clicked. The insert_cell function inserts a new cell with a code comment.

Step 6: Install and Enable the Extension

You’ll notice a new “plane” icon when you edit or create a new notebook.

The Planet Jupyter Extension in action ….

Step 7: Continue to Develop your Extension

$ jupyter nbextension install planet_jupyter
$ jupyter nbextension enable planet_jupyter/main

--

--

Data Science, Topic Modelling, Deep Learning, Algorithm Usability and Interpretation, Learning Analytics, Electronics — Brisbane, Australia

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Aneesha Bakharia

Data Science, Topic Modelling, Deep Learning, Algorithm Usability and Interpretation, Learning Analytics, Electronics — Brisbane, Australia