plotly.py: Plotly plots not working in Jupyterlab
When I run this example:
import plotly.graph_objects as go
fig = go.Figure(data=go.Bar(y=[2, 3, 1]))
fig.show()
in a Jupyter notebook under jupyter lab I get no output. The output cell expands as if it is going to show output, but it is just blank. I see this error in the browser console:
VM458:2 Uncaught ReferenceError: require is not defined
at <anonymous>:2:17
at t.attachWidget (vendors~main.479571ea0f6c7741ac01.js:2)
at t.insertWidget (vendors~main.479571ea0f6c7741ac01.js:2)
at C._insertOutput (vendors~main.479571ea0f6c7741ac01.js:2)
at C.onModelChanged (vendors~main.479571ea0f6c7741ac01.js:2)
at m (vendors~main.479571ea0f6c7741ac01.js:2)
at Object.c [as emit] (vendors~main.479571ea0f6c7741ac01.js:2)
at e.emit (vendors~main.479571ea0f6c7741ac01.js:2)
at f._onListChanged (vendors~main.479571ea0f6c7741ac01.js:2)
at m (vendors~main.479571ea0f6c7741ac01.js:2)
Googling I see others that had that problem had bad installs of extensions, I don’t think I have that:
My jupyterlab + extension versions are:
xbk@30c1f8a93eeb:~/xbk_trade_advisory/code/chquery$ jupyter --version
jupyter core : 4.6.2
jupyter-notebook : 6.0.3
qtconsole : 4.7.1
ipython : 7.12.0
ipykernel : 5.1.4
jupyter client : 5.3.4
jupyter lab : 2.0.1
nbconvert : 5.6.1
ipywidgets : 7.5.1
nbformat : 5.0.4
traitlets : 4.3.3
xbk@30c1f8a93eeb:~/xbk_trade_advisory/code/chquery$ jupyter labextension list
JupyterLab v2.0.1
Known labextensions:
app dir: /usr/local/share/jupyter/lab
@jupyter-widgets/jupyterlab-manager v2.0.0 enabled OK
jupyterlab-plotly v4.9.0 enabled OK
plotlywidget v4.9.0 enabled OK
Thanks for any help with this.
Matt
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 17
- Comments: 26 (4 by maintainers)
I managed to make it work in jupyter lab using:
I figured out that setting
pio.renderers.default
toiframe
,iframe_connected
, orbrowser
works. But notjupyterlab
ornotebook
. When set tonotebook
an empty space shows up where the plot is supposed to be, when set tojupyterlab
, it finishes the computation and nothing happens.I got it working by installing the “jupyterlab-plotly” extension.
In the anaconda command prompt:
and then
Even though I am using jupyterlab version 3.0.14 and it says in the documents that we don’t need to install extra extensions for jupyterlab. But it seems that’s not the case for me.
now when I use:
I get the outupt in my jupyterlab notebook as:
I’ve got the same issue with latest version of Lab & Dash: https://github.com/plotly/jupyter-dash/issues/57
I too tried all of the above without any joy. The thing that ended up working for me was to reset the application state (after first installing the
jupyterlab-plotly
lab extension and runningjupyter lab build
) which can be done through the JupyterLab UI by doing the following:I’ve attached a GIF of this process for clarity:
For reference, my lab extensions look like the following:
And my method of actually rendering the plot is to use
iplot
:Right, so JupyterLab and Classic Notebook have two completely different rendering paths.
fig.show("notebook")
works in Classic Notebook and doesn’t require any special installation of extensions, and is not intended to work in JupyterLab.fig.show("jupyterlab")
works in JupyterLab and requires thejupyterlab-plotly
JupyterLab extension to be installed.The renderer system auto-detects the notebook vs lab environment and sets the default mode for the current environment, so in principle you shouldn’t need to specify the mode by passing anything into
fig.show()
.If things aren’t working for you in JupyterLab, then something is wrong with the
jupyterlab-plotly
extension for some reason. It’s strange that you see no output but also no error in this mode… I’m not quite sure what more to suggest in this case!I got it working using the steps from here https://github.com/plotly/plotly_express/issues/38 because I had similar js errors in my browser console log.
The exact commands I used were as follows
I’m not sure exactly which extension was causing issues but hope this helps someone else.