The world’s leading publication for data science, AI, and ML professionals.

Jupyter Lab: Evolution of the Jupyter Notebook

All good things (must) come to an end to make way for something better.

An overview of JupyterLab, the next generation of the Jupyter Notebook.

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.


Jupyter Lab

Source
Source

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.


Table of Contents

  1. Installation
  2. Interface
  3. Creating and Saving Files
  4. Flexible Layouts
  5. Enhanced Notebook Functionality
  6. Supported File Formats
  7. Interactive Computing
  8. Extensions
  9. Conclusion

In case you are completely unfamiliar with Jupyter Lab, you can start reading the article right from Installation. But if you have already worked with them and want an advanced overview, skip the first four parts and jump straight to part 5 making sure that you are using the latest release.


1. Installation

Jupyterlab can be installed using conda, pip or pipenv.

#conda
conda install -c conda-forge jupyterlab
#pip
pip install jupyterlab
#pipenv
pipenv install jupyterlab
pipenv shell

Have a look at the official installation documentation for more details.

Starting JupyterLab

You can start the Jupyter by simply typing the following at the console:

jupyter lab

JupyterLab will open automatically in the browser with an interface resembling the one below. This means everything is in place and you are good to go.

Since I use both Python and R in Jupyter Lab, my worksheet has icons for both of them.

🔝


2. Interface

Let’s understand a bit about the interface before working with its various functionalities.

  • Menu Bar

The Menu Bar has the top-level menus that showcase the various actions that are available in Jupyter Lab.

  • Left Sidebar

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.

  • Main Work Area

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.

🔝


3. Creating and Saving Files

In this section, we will quickly see how to work with files in Jupyter Lab.

Creating Files

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 Existing Files

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.

4. Flexible Layouts

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.

Different blocks in a classic Network which worked independently
Different blocks in a classic Network which worked independently

Jupyter Lab tends to plug this pain area by integrating all the features into a single interactive and collaborative environment.

  • Notebooks

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.

  • Console

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.

  • Text Editor

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.

  • Terminal

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.

🔝


5. Enhanced Notebook Functionality

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:

Expand and Collapse cells

Drag and Drop cells within the Notebook

Tab Autocompletion in the Editor

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.

Themes

There are themes available for the JupyterLab as a whole and for the Text Editors as well.

🔝


6. Supported File Formats

Jupyter Lab also supports other formats like :

  • Images: jpeg, png etc and Gifs
  • geojson
  • Vegalite files, geojson files,
  • PDF Documents
  • High-Performance CSV viewer

A Jupyter Lab can basically render arbitrarily large CSVs s which are typically rendered as unresponsive in Excel. It is not very interactive as yet but some improvements may be expected soon.

🔝


7. Interactive Computing

The real capabilities of Jupyter Lie in the fact that it supports interactive computing which is very useful in Data Science particularly.

Creating New View for Output

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.

New View on the same file

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.

Dragging / Dropping and Editing Cells between Notebooks

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.

Simplifying the Code Documentation Process

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.

🔝


8. Extensions

JupyterLab has been designed as an essentially extensible environment. The extensions are really powerful tools that can really enhance a person’s productivity. JupyterLab extensions are npm packages (the standard package format in Javascript development). There are many community-developed extensions being built on GitHub. You can search for the GitHub topic jupyterlab-extension to find extensions.

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

Installing Extensions

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 protected]

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.

Installation

jupyter labextension install @jupyterlab/google-drive

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.

source
source

Usage

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.

Installation

jupyter labextension install @jupyterlab/github

After installation, we need to get the credentials from GitHub. For more details please read the instructions here.

Usage

jupyterlab-git is a JupyterLab extension for version control using git.

Installation

To install perform the following steps:

jupyter labextension install @jupyterlab/git
pip install jupyterlab-git
jupyter serverextension enable --py jupyterlab_git

Usage

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.

Installation

jupyter labextension install jupyterlab-drawio

Usage

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.

🔝


Conclusion

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.


Related Articles