Three Jupyter Notebook Extensions That Minimize Distractions | by Lukas Frei | Towards Data Science

Jupyter notebook extensions, also known as nbextensions, are tools to help you improve your productivity. They provide many useful features, such as the so-called “Variable Inspector” that lets you keep track of all the variables you have defined. Nevertheless, there is a particular class of some lesser known nbextensions: those that focus on minimizing distractions. In this article, I’m first going to explain to you how to install nbextensions and then introduce three nbextensions that will increase your productivity by minimizing distractions.
There are several ways to install nbextensions. You could, for instance, install the nbextensions separately one by one, however, there is a more convenient way. On top of installing jupyter_contrib_nbextensions, additionally installing jupyter_nbextensions_configurator will provide handy ways to manage the nbextensions.
Then, run the following code chunk in your terminal to install both simultaneously:
conda install -c conda-forge jupyter_contrib_nbextensions jupyter_nbextensions_configurator
After having installed nbextensions and the configurator, you can see all of the available extensions as well as activate them by navigating to localhost:6006/extensions.
Now that all requirements have been installed, let us take a look at the three previously mentioned nbextensions:
This extension is exactly what it sounds like. The scratchpad notebook extension allows you to run code against the current kernel without having to constantly add new cells in between your actual code for experimentation or calculation purposes. Open your scratchpad with Shift+Enter and close it via Ctrl+B.
If you should be an avid RStudio user, you are probably missing the structure code folding creates when using Juypter notebooks. This extension solves this problem. There are three supported code folding options:
The algorithm detects indents and allows you to fold indents one by one. This means that you have more flexibility regarding the amount of code you would like to fold.
To visualize this, let’s take a look at the following code cell:
As you can see, there are two indents. Thus, this code cell can be folded into:
And also into:
Another option is to fold cells that have a comment in their first line. This would then result in only the comment in the first line being displayed instead of the entire cell. In doing so, you could keep a short and precise description of the cell in the first line while removing the code.
Thus, the following cell...
...can be folded into:
The same concept applies to magic commands in the first line. This particular folding option could be particularly useful for cells that import packages. Another application for this option is to remove all code that is not Python to avoid possible distractions.
Folding will turn the above cell into:
Additionally, all of your folds will be saved upon saving your Jupyter notebook.
The third and final nbextension I am going to introduce in this article is probably the most mentioned out of the three. The zenmode extension will remove the menu and enable you to focus on your code. In my opinion, this will also make the Jupyter notebook interface visually more attractive in general.
The following GIF illustrates the above:
Making small changes to your work environment can have great impacts on your productivity. Minimizing distractions and completely focusing on coding is one of the most important goals when it comes to designing one’s work environment and using nbextensions is a neat way to do so. Of course, these three extensions do not capture all that nbextensions have to offer. Thus, if you should be keen on learning more, I would recommend you to dive into the documentation.
References:
[1] Unofficial Jupyter Notebook Extensions Documentation