Jupyter Notebook Extensions
You've mastered the basics, now let us look at possible extensions to enhance your Notebook
To get extensions in your Jupyter Notebook environment you’ll first need to install ‘Nbextensions’. This can be done through PIP or through Anaconda Prompt depending on how you originally installed Jupyter. For PIP users type:
pip install jupyter_contrib_nbextensions && jupyter contrib nbextension install
For Anaconda users type into the Anaconda Prompt:
conda install -c conda-forge jupyter_contrib_nbextensions
Following this with a refresh of the Jupyter environment you should now see an ‘Nbextensions’ tab on your homepage environment. Sometimes this doesn’t happen, try typing this into the terminal or Anaconda environment:
jupyter nbextensions_configurator enable --user
This should with another refresh show the tab. If it does not and the problem persists check out this github post about other common issues and run down them.
Now we are all set up we can start to explore some of these extensions. The first thing you will notice when clicking on the tab is that there is a lot of possible extensions.
It won’t be feasible to go over all of these in one post so I will focus on a few that should be very useful to implement but go through and click on all of them - a brief description .md file and an image of what each extension does should be visible to you.
Move Selected Cells
The move selected cells extension allows you to avoid the need to enter into command mode. With this extension, you can simply use alt + up or alt + down to move cells or groups of cells.
Hinterland
This extension adds an autocomplete feature to Jupyter. This is a great extension for those of you (myself included) who type faster than we think.
Hide Input and Hide Input All
Often times we never want to hide our code. It inhibits open science practices. However, some circumstances can call for hiding some of our code - this may be useful if you are merging lots of datasets together and need to use the ‘cd’ and ‘use’ commands in Stata a lot. A comment saying you are doing this, instead of showing every instance of this code would suffice. This extension allows you to hide portions of your cells.
Table of Contents (2)
If the intention in using Jupyter Notebook is to write good code and produce a report able to be replicated, you will end up with a large Notebook. This extension fathers all the headings available in your Markdown cells and shows them in the sidebar, making browsing much easier.
Spellchecker
Another amazing extension if like myself, you type far too quickly. As the name suggests, the spellchecker extension highlights any spelling errors in the Markdown cells.
Collapsible Headings
This extension is similar to the way headings work in Word. It simply adds the ability to collapse everything within that Mardown heading. The collapsed status of the headers is also saved in the cell metadata and reloaded when you reload the Notebook.
AutoSaveTime
This extension allows you to change how often your Notebook autosaves. If you are conscious of crashes etc then you can shorten them, or if you are running this instance on a weaker machine, elongate the autosave.
Execute Time
After executing a code cell a stamp will be placed by the cell on the date and time executed as well as how long it took for the code to execute. This is great for open science practices (combatting P-Hacking, HARKing etc) as well as helping you improve efficiency on your code.
nbTranslate
This extension is great when you are reading other people’s Notebooks and they are using a different language to your own. It translates comments for you.
Highlighter
This extension adds the ability to highlight Markdown comments within your Notebook.
Beyond Extensions
Beyond the extensions used in nbextensions two more vital ‘additions’ to Jupyter should be mentioned. The first is integrated into Jupyter already - multicursor support. Jupyter supports multiple cursors. Simply click and drag your mouse while holding down Alt. This is exceptionally useful for researchers engaging in occupational data that have to manually recode SOC codes etc.
The second and most powerful of all extensions is probably ‘RISE’. RISE is an extension that allows you to convert in real-time your entire (or individual sections if you want) Jupyter Notebook into a PowerPoint-like presentation. To use RISE you will first need to install it, again either via PIP:
pip install RISE
or via Anaconda Prompt:
conda install -c conda-forge rise
RISE should then be automatically selected in your nbextensions configuration.
Note for Older macOS (Sierra 10.12 or older)
If you are using a very old macOS you will run into lots of issues when attempting to add extensions to your Jupyter Notebook. This will primarily come from an issue with PIP rather than the extensions themselves. This may be overcome by installing:
curl https://bootstrap.pypa.io/get-pip.py | python
Which uninstalls PIP and reinstalls it to the most up-to-date version - then you can proceed with downloading the extensions. Sometimes this just does not work, however. I have yet to find a solution to this.