All good things (must) come to an end to make way for something better.
Data says there are more than three million Jupyter Notebooks available publicly on Github. There is roughly a similar number of private ones too. Even without this data, we are quite aware of the popularity of the notebooks in the Data Science domain. The possibility of writing codes, inspecting the results, getting rich outputs are some of the features that really made Jupyter Notebooks very popular. But as it is said that all good things (must) come to an end, so will our favourite Notebook too. JupyterLab will eventually replace the classic Jupyter Notebook but for good.
Some time back I published a guide on using Classic Jupyter Notebooks effectively. But as will be seen, JupyterLab is the next-generation user interface for Project Jupyter offering all the familiar building blocks of the classic Jupyter Notebook (notebook, terminal, text editor, file browser, rich outputs, etc.) in a flexible and a more powerful user interface. The basic idea of the Jupyter Lab is to bring all the building blocks that are in the classic notebook, plus some new stuff, under one roof.
JupyterLab can be installed using conda, pip or pipenv.
Let’s understand a bit about the interface before working with its various functionalities.
The Menu Bar has the top-level menus that showcase the various actions that are available in Jupyter Lab.
This consists of the commonly-used tabs. The left sidebar can be collapsed or expanded by selecting Show Left Sidebar in the View menu or by clicking on the active sidebar tab.
You can view the running session from the Running palette while the Commands palette lets you search for all the commands that are available.
This is the area where the actual activity takes place. It comprises of the notebooks, documents, consoles, terminals etc. Just double click or drag a file on to this area to start working. Workspaces can be saved on the server with named workspace URLs.
Also, you can switch between the classic Notebook view and the JupyterLab view by changing the lab to tree in the url of the Jupyter Lab.
In this section, we will quickly see how to work with files in Jupyter Lab.
Simply click on the + icon in the main menu. This opens a new Launcher tab in the main work area could enabling us to create a Notebook, Console, terminal or text editor. The same action can also be achieved by using the File tab. Once opened, the files can be renamed and even downloaded.
Opening files is a very straightforward process. Either double click on them or access them through the upper File Tab.
These were just the basics of Jupyter Lab , essentially to get started. Now let’s move on to the part where we discuss its real capabilities and what makes it superior to classic Notebooks.
The classic Jupyter Notebook also supports an inbuilt Text Editor and a Terminal but these options aren’t used much since they are mostly hidden from sight. Another reason is that all these components work as standalone features and not integrated.
Jupyter Lab tends to plug this pain area by integrating all the features into a single interactive and collaborative environment.
The notebook document format used in JupyterLab is the same as in the classic Jupyter Notebook. The existing notebooks should open correctly in JupyterLab and we can do our regular analysis in there.
There are consoles for people who are used to a QT console type environment. These consoles enable us to run code interactively in a kernel.
The text editor makes it possible to edit the files. The text editor includes syntax highlighting, configurable indentation (tabs or spaces), key maps and basic theming. These settings can be found in the Settings menu.
JupyterLab terminal provides full support for system shells (bash, tsch, etc.) on Mac/Linux and PowerShell on Windows. We can run anything in our system shell with a terminal, including programs such as vim or emacs.
Now, one would say that all these features were present in the classic notebook too so what makes Jupyter Lab different. The fact that it gives us a very flexible layout system which allows us to take these tabs, drag them side-by-side and resize them with almost unlimited flexibility is something that was missing earlier.
Jupyter lab is not a reimplementation of the notebook format but just a new front-end that exists on top of all of the existing architecture. However, this new front end implementation has made it possible to include features that we missed in the classic notebooks. Some of the features are:
The text editors now have the code autocompletion feature. However, as of now, it is only enabled when there is an attached console to the text editor.
There are themes available for the JupyterLab as a whole and for the Text Editors as well.
The real capabilities of Jupyter Lie in the fact that it supports interactive computing which is very useful in Data Science particularly.
I’ll be using the Lorenz differential equations notebook from the official Jupyter Github page. After running a few cells, we get the interactive Lorenz attractor as the output. Sometimes when we have an interactive output, it gets kind of frustrating having to scroll up and down to the code that generates it. As a solution to this problem, Jupyter Lab gives us an option to break the output into a new tab and we have a kind of pseudo dashboard where we can use the sliders and change the parameters.
Sometimes our notebook is too long and so we can have two views of the same(or different) notebooks in a single instance. This could be useful when we want to look at the top and bottom of the notebook at the same time.
We know the cells can be dragged within a notebook. However, the cells can also be dragged across different Notebooks. Also, the changes in one Notebook is reflected into the other as well.
It is rightly said that Code is read more often than it is written. Documentation is a very important aspect of programming and Jupyter Lab tends to make it easier. One of the problems that I really face when writing documentation in a markdown file is that I have to run the code in a different console to check if it is running perfectly and then include it in the file. Switching tabs, again and again, is annoying.
Jupyter Labs lets you combine the editor and console into a single view. So you can check your code and your documentation and preview the entire file at the same time.
In order to install JupyterLab extensions, you need to have Node.js installed which can either be installed from their website or as follows.
conda install -c conda-forge nodejs or brew install node
New extensions can be installed by using the following command:
jupyter labextension install <my-extension>
where where my-extension is the name of a valid JupyterLab extension npm package on npm. Use the my-extension@version syntax to install a specific version of an extension, for example:
jupyter labextension install email@example.com
For more details, please refer to the official documentation on extensions. Let’s talk about a few extensions which I use a lot and are really powerful:
This extension adds a Google Drive file browser to the left side panel of JupyterLab. When you are logged into your Google account, you will have the files stored in it available to JupyterLab.
Apart from installing the extension, you will also have to authenticate your JupyterLab deployment with Google. Go through the setup file or the link here for the process. You will get a client ID which you will have to manually enter.
Now, if someone shares a notebook or a markdown file, it will reflect in the shared with me folder in Jupyter Lab. We can open and edit it there itself.
It is a JupyterLab extension for accessing GitHub repositories. This extension allows us to select GitHub organizations and users, browse their repositories, and open the files in those repositories. If those files are notebooks, we can run them just as we would run any other notebook.
jupyter labextension install @jupyterlab/github
After installation, we need to get the credentials from GitHub. For more details please read the instructions here.
jupyterlab-git is a JupyterLab extension for version control using git.
Drawio plugin is a JupyterLab extension for standalone integration of drawio into Jupyterlab. draw.io is a free online diagram software for making flowcharts, process diagrams, org charts, UML, ER and network diagrams.
jupyter labextension install jupyterlab-drawio
These extensions really make the JupyterLab stand out. Having all the tools in a single workplace makes it very useful since one doesn’t have to switch between different environments to get the things done. Apart from the above extensions there are many others and feel free to try them out too.
JupyterLab is truly the next-generation web-based user interface. It is loaded with tools for interactive computing and well-designed interface that allows users to combine them in novel ways. It is really powerful and provides a great variety of robust tools which will make the Data Analysis process much smoother and definitely more productive.