Plotly gives an empty field as output in jupyter lab

To properly display the plotly offline graphs in JupyterLab,

Step 1: We need to first install the plotly-extension for JupyterLab:

$ jupyter labextension install @jupyterlab/plotly-extension

(Note that the above step requires Node.js >= 4, if Node.js is not available on your OS, install it from its Official Website.)

Step 2: Check the status after the installation of @jupyterlab/plotly-extension:

$ jupyter labextension list 
JupyterLab v0.35.5
Known labextensions:
   app dir: /Users/yourname/anaconda3/share/jupyter/lab
        @jupyterlab/plotly-extension v0.18.2  enabled  OK

Build recommended, please run `jupyter lab build`:
    @jupyterlab/plotly-extension needs to be included in build

Step 3: Follow the suggestion, re-build the JupyterLab with its newly installed labextensions:

$ jupyter lab build

After these, restart JupyterLab, and set plotly.offline.init_notebook_mode(connected=True) at the start of each notebook session, then plotly.offline.iplot should correctly display the plots in the notebook.


@YaOzI answer is partially correct but @jupyterlab/plotly-extension is deprecated and not supported by the official plotly team as you can read here.

This can give you the following error:

ValueError: The extension "@jupyterlab/plotly-extension" does not yet support the current version of JupyterLab.


Conflicting Dependencies:
JupyterLab                        Extension      Package
>=2.2.1 <2.3.0                    >=1.3.0 <2.0.0 @jupyterlab/rendermime-interfaces
See the log file for details:  /tmp/jupyterlab-debug-a3i3t9j4.log

>>> TL;DR:

Following the official advice, this is what worked for me (make sure your kernel is shut down, otherwise you will need to run jupyter lab build):

jupyter labextension install jupyterlab-plotly

And (just to be sure it worked):

jupyter labextension list

May give you something like this:

JupyterLab v2.2.9
Known labextensions:
   app dir: /home/user/anaconda3/envs/your-py-env/share/jupyter/lab
        jupyterlab-dash v0.3.0  enabled  OK
        jupyterlab-plotly v4.14.1  enabled  OK


Installing extensions for Jupyter lab has changed for version > 3.0.

To see how the make plotly work in Jupyter lab. Check the packages that need to be installed in the official documentation