Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plotly plots not working in Jupyterlab #2672

Closed
mvcalder-xbk opened this issue Jul 28, 2020 · 27 comments
Closed

Plotly plots not working in Jupyterlab #2672

mvcalder-xbk opened this issue Jul 28, 2020 · 27 comments

Comments

@mvcalder-xbk
Copy link

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

@shrestha-pranav
Copy link

I have the same issues, with the same browser console error.

$ jupyter --version
jupyter core     : 4.6.3
jupyter-notebook : 6.1.3
qtconsole        : not installed
ipython          : 7.8.0
ipykernel        : 5.3.4
jupyter client   : 6.1.6
jupyter lab      : 2.2.5
nbconvert        : 5.6.1
ipywidgets       : 7.5.0
nbformat         : 5.0.7
traitlets        : 4.3.2
JupyterLab v2.2.5
Known labextensions:
   app dir: /local/mnt/workspace/user/.virtualenvs/nnpy/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

Figures show up fine in Jupyter Notebook however. Any help would be appreciated.

@shrestha-pranav
Copy link

I got it working using the steps from here plotly/plotly_express#38 because I had similar js errors in my browser console log.

The exact commands I used were as follows

export NODE_OPTIONS=--max-old-space-size=4096
jupyter labextension list
jupyter labextension install @jupyter-widgets/jupyterlab-manager --no-build
jupyter labextension install [email protected] --no-build
jupyter labextension install [email protected] --no-build
jupyter labextension install jupyterlab-chart-editor --no-build
jupyter lab build
unset NODE_OPTIONS
jupyter lab

I'm not sure exactly which extension was causing issues but hope this helps someone else.

@JanHomann
Copy link

This is the same issue as #2742 I suspect.

@JanHomann
Copy link

JanHomann commented Sep 4, 2020

I have the same problem with the same error in the brower javascript console both in Safari and Chrome. The solution by @shrestha-pranav did not fix it for me. Plotly works in jupyter notebook.

$ jupyter --version
jupyter core     : 4.6.3
jupyter-notebook : 6.1.3
qtconsole        : not installed
ipython          : 7.18.1
ipykernel        : 5.3.4
jupyter client   : 6.1.7
jupyter lab      : 2.2.6
nbconvert        : 5.6.1
ipywidgets       : 7.5.1
nbformat         : 5.0.7
traitlets        : 4.3.3
$ jupyter labextension list
JupyterLab v2.2.6
Known labextensions:
   app dir: /Users/janhomann/opt/anaconda3/envs/JupyterLabTest/share/jupyter/lab
        @jupyter-widgets/jupyterlab-manager v2.0.0  enabled  OK
        jupyterlab-chart-editor v4.9.0  enabled  OK
        jupyterlab-dash v0.3.0  enabled  OK
        jupyterlab-plotly v4.9.0  enabled  OK
        plotlywidget v4.9.0  enabled  OK

@JanHomann
Copy link

I figured out that setting pio.renderers.default to iframe, iframe_connected, or browser works. But not jupyterlab or notebook. When set to notebook an empty space shows up where the plot is supposed to be, when set to jupyterlab, it finishes the computation and nothing happens.

@nicolaskruchten
Copy link
Contributor

In some cases I've found that just running jupyter lab build on the command line fixes this issue, even though in principle it shouldn't. Worth a try!

Either way, if folks could share their NodeJS version as well, that might help pinpoint a common cause for these issues.

@JanHomann
Copy link

Hi Nicolas. jupyter lab build didn't help. And my node.js version is v14.9.0 as far as i can see (typing node -v in the terminal)

@nicolaskruchten
Copy link
Contributor

Ok, thanks for that version! What error message appears in the JS console when you render a plot and see no output?

@JanHomann
Copy link

Uncaught ReferenceError: require is not defined
    at <anonymous>:2:17
    at t.attachWidget (vendors~main.b10336539d1031afa7d6.js:2)
    at t.insertWidget (vendors~main.b10336539d1031afa7d6.js:2)
    at _insertOutput (vendors~main.b10336539d1031afa7d6.js:2)
    at _.onModelChanged (vendors~main.b10336539d1031afa7d6.js:2)
    at v (vendors~main.b10336539d1031afa7d6.js:2)
    at Object.u [as emit] (vendors~main.b10336539d1031afa7d6.js:2)
    at e.emit (vendors~main.b10336539d1031afa7d6.js:2)
    at u._onListChanged (vendors~main.b10336539d1031afa7d6.js:2)
    at v (vendors~main.b10336539d1031afa7d6.js:2)

@JanHomann
Copy link

This is the renderer configuration that it has.

>>> import plotly.io as pio
>>> pio.renderers
Renderers configuration
-----------------------
    Default renderer: 'plotly_mimetype+notebook'
    Available renderers:
........

when i do
fig.show(renderer = 'jupyterlab')

nothing happens and no error shows up in the java script console.

when i do
fig.show(renderer = 'notebook')

i get a blank space and the error shows up in the java script console. So I assume it does the notebook renderer when i don't specify anything.

@JanHomann
Copy link

In chrome i can click on 'require not defined` and this code shows up:

                require(["plotly"], function(Plotly) {
                    window.PLOTLYENV=window.PLOTLYENV || {};
                    
                if (document.getElementById("e7921b12-5927-4af5-a39f-cd49b021efe1")) {
                    Plotly.newPlot(
                        'e7921b12-5927-4af5-a39f-cd49b021efe1',
                        [{"type": "bar", "y": [2, 1, 3]}],
                        {"template": {"data": {"bar": [{"error_x": {"color": "#2a3f5f"}, "error_y": {"color": "#2a3f5f"}, "marker": {"line": {"color": "#E5ECF6", "width": 0.5}}, "type": "bar"}], "barpolar": [{"marker": {"line": {"color": "#E5ECF6", "width": 0.5}}, "type": "barpolar"}], "carpet": [{"aaxis": {"endlinecolor": "#2a3f5f", "gridcolor": "white", "linecolor": "white", "minorgridcolor": "white", "startlinecolor": "#2a3f5f"}, "baxis": {"endlinecolor": "#2a3f5f", "gridcolor": "white", "linecolor": "white", "minorgridcolor": "white", "startlinecolor": "#2a3f5f"}, "type": "carpet"}], "choropleth": [{"colorbar": {"outlinewidth": 0, "ticks": ""}, "type": "choropleth"}], "contour": [{"colorbar": {"outlinewidth": 0, "ticks": ""}, "colorscale": [[0.0, "#0d0887"], [0.1111111111111111, "#46039f"], [0.2222222222222222, "#7201a8"], [0.3333333333333333, "#9c179e"], [0.4444444444444444, "#bd3786"], [0.5555555555555556, "#d8576b"], [0.6666666666666666, "#ed7953"], [0.7777777777777778, "#fb9f3a"], [0.8888888888888888, "#fdca26"], [1.0, "#f0f921"]], "type": "contour"}], "contourcarpet": [{"colorbar": {"outlinewidth": 0, "ticks": ""}, "type": "contourcarpet"}], "heatmap": [{"colorbar": {"outlinewidth": 0, "ticks": ""}, "colorscale": [[0.0, "#0d0887"], [0.1111111111111111, "#46039f"], [0.2222222222222222, "#7201a8"], [0.3333333333333333, "#9c179e"], [0.4444444444444444, "#bd3786"], [0.5555555555555556, "#d8576b"], [0.6666666666666666, "#ed7953"], [0.7777777777777778, "#fb9f3a"], [0.8888888888888888, "#fdca26"], [1.0, "#f0f921"]], "type": "heatmap"}], "heatmapgl": [{"colorbar": {"outlinewidth": 0, "ticks": ""}, "colorscale": [[0.0, "#0d0887"], [0.1111111111111111, "#46039f"], [0.2222222222222222, "#7201a8"], [0.3333333333333333, "#9c179e"], [0.4444444444444444, "#bd3786"], [0.5555555555555556, "#d8576b"], [0.6666666666666666, "#ed7953"], [0.7777777777777778, "#fb9f3a"], [0.8888888888888888, "#fdca26"], [1.0, "#f0f921"]], "type": "heatmapgl"}], "histogram": [{"marker": {"colorbar": {"outlinewidth": 0, "ticks": ""}}, "type": "histogram"}], "histogram2d": [{"colorbar": {"outlinewidth": 0, "ticks": ""}, "colorscale": [[0.0, "#0d0887"], [0.1111111111111111, "#46039f"], [0.2222222222222222, "#7201a8"], [0.3333333333333333, "#9c179e"], [0.4444444444444444, "#bd3786"], [0.5555555555555556, "#d8576b"], [0.6666666666666666, "#ed7953"], [0.7777777777777778, "#fb9f3a"], [0.8888888888888888, "#fdca26"], [1.0, "#f0f921"]], "type": "histogram2d"}], "histogram2dcontour": [{"colorbar": {"outlinewidth": 0, "ticks": ""}, "colorscale": [[0.0, "#0d0887"], [0.1111111111111111, "#46039f"], [0.2222222222222222, "#7201a8"], [0.3333333333333333, "#9c179e"], [0.4444444444444444, "#bd3786"], [0.5555555555555556, "#d8576b"], [0.6666666666666666, "#ed7953"], [0.7777777777777778, "#fb9f3a"], [0.8888888888888888, "#fdca26"], [1.0, "#f0f921"]], "type": "histogram2dcontour"}], "mesh3d": [{"colorbar": {"outlinewidth": 0, "ticks": ""}, "type": "mesh3d"}], "parcoords": [{"line": {"colorbar": {"outlinewidth": 0, "ticks": ""}}, "type": "parcoords"}], "pie": [{"automargin": true, "type": "pie"}], "scatter": [{"marker": {"colorbar": {"outlinewidth": 0, "ticks": ""}}, "type": "scatter"}], "scatter3d": [{"line": {"colorbar": {"outlinewidth": 0, "ticks": ""}}, "marker": {"colorbar": {"outlinewidth": 0, "ticks": ""}}, "type": "scatter3d"}], "scattercarpet": [{"marker": {"colorbar": {"outlinewidth": 0, "ticks": ""}}, "type": "scattercarpet"}], "scattergeo": [{"marker": {"colorbar": {"outlinewidth": 0, "ticks": ""}}, "type": "scattergeo"}], "scattergl": [{"marker": {"colorbar": {"outlinewidth": 0, "ticks": ""}}, "type": "scattergl"}], "scattermapbox": [{"marker": {"colorbar": {"outlinewidth": 0, "ticks": ""}}, "type": "scattermapbox"}], "scatterpolar": [{"marker": {"colorbar": {"outlinewidth": 0, "ticks": ""}}, "type": "scatterpolar"}], "scatterpolargl": [{"marker": {"colorbar": {"outlinewidth": 0, "ticks": ""}}, "type": "scatterpolargl"}], "scatterternary": [{"marker": {"colorbar": {"outlinewidth": 0, "ticks": ""}}, "type": "scatterternary"}], "surface": [{"colorbar": {"outlinewidth": 0, "ticks": ""}, "colorscale": [[0.0, "#0d0887"], [0.1111111111111111, "#46039f"], [0.2222222222222222, "#7201a8"], [0.3333333333333333, "#9c179e"], [0.4444444444444444, "#bd3786"], [0.5555555555555556, "#d8576b"], [0.6666666666666666, "#ed7953"], [0.7777777777777778, "#fb9f3a"], [0.8888888888888888, "#fdca26"], [1.0, "#f0f921"]], "type": "surface"}], "table": [{"cells": {"fill": {"color": "#EBF0F8"}, "line": {"color": "white"}}, "header": {"fill": {"color": "#C8D4E3"}, "line": {"color": "white"}}, "type": "table"}]}, "layout": {"annotationdefaults": {"arrowcolor": "#2a3f5f", "arrowhead": 0, "arrowwidth": 1}, "coloraxis": {"colorbar": {"outlinewidth": 0, "ticks": ""}}, "colorscale": {"diverging": [[0, "#8e0152"], [0.1, "#c51b7d"], [0.2, "#de77ae"], [0.3, "#f1b6da"], [0.4, "#fde0ef"], [0.5, "#f7f7f7"], [0.6, "#e6f5d0"], [0.7, "#b8e186"], [0.8, "#7fbc41"], [0.9, "#4d9221"], [1, "#276419"]], "sequential": [[0.0, "#0d0887"], [0.1111111111111111, "#46039f"], [0.2222222222222222, "#7201a8"], [0.3333333333333333, "#9c179e"], [0.4444444444444444, "#bd3786"], [0.5555555555555556, "#d8576b"], [0.6666666666666666, "#ed7953"], [0.7777777777777778, "#fb9f3a"], [0.8888888888888888, "#fdca26"], [1.0, "#f0f921"]], "sequentialminus": [[0.0, "#0d0887"], [0.1111111111111111, "#46039f"], [0.2222222222222222, "#7201a8"], [0.3333333333333333, "#9c179e"], [0.4444444444444444, "#bd3786"], [0.5555555555555556, "#d8576b"], [0.6666666666666666, "#ed7953"], [0.7777777777777778, "#fb9f3a"], [0.8888888888888888, "#fdca26"], [1.0, "#f0f921"]]}, "colorway": ["#636efa", "#EF553B", "#00cc96", "#ab63fa", "#FFA15A", "#19d3f3", "#FF6692", "#B6E880", "#FF97FF", "#FECB52"], "font": {"color": "#2a3f5f"}, "geo": {"bgcolor": "white", "lakecolor": "white", "landcolor": "#E5ECF6", "showlakes": true, "showland": true, "subunitcolor": "white"}, "hoverlabel": {"align": "left"}, "hovermode": "closest", "mapbox": {"style": "light"}, "paper_bgcolor": "white", "plot_bgcolor": "#E5ECF6", "polar": {"angularaxis": {"gridcolor": "white", "linecolor": "white", "ticks": ""}, "bgcolor": "#E5ECF6", "radialaxis": {"gridcolor": "white", "linecolor": "white", "ticks": ""}}, "scene": {"xaxis": {"backgroundcolor": "#E5ECF6", "gridcolor": "white", "gridwidth": 2, "linecolor": "white", "showbackground": true, "ticks": "", "zerolinecolor": "white"}, "yaxis": {"backgroundcolor": "#E5ECF6", "gridcolor": "white", "gridwidth": 2, "linecolor": "white", "showbackground": true, "ticks": "", "zerolinecolor": "white"}, "zaxis": {"backgroundcolor": "#E5ECF6", "gridcolor": "white", "gridwidth": 2, "linecolor": "white", "showbackground": true, "ticks": "", "zerolinecolor": "white"}}, "shapedefaults": {"line": {"color": "#2a3f5f"}}, "ternary": {"aaxis": {"gridcolor": "white", "linecolor": "white", "ticks": ""}, "baxis": {"gridcolor": "white", "linecolor": "white", "ticks": ""}, "bgcolor": "#E5ECF6", "caxis": {"gridcolor": "white", "linecolor": "white", "ticks": ""}}, "title": {"x": 0.05}, "xaxis": {"automargin": true, "gridcolor": "white", "linecolor": "white", "ticks": "", "title": {"standoff": 15}, "zerolinecolor": "white", "zerolinewidth": 2}, "yaxis": {"automargin": true, "gridcolor": "white", "linecolor": "white", "ticks": "", "title": {"standoff": 15}, "zerolinecolor": "white", "zerolinewidth": 2}}}, "title": {"text": "A Figure Displayed with the 'svg' Renderer"}},
                        {"responsive": true}
                    ).then(function(){
                            
var gd = document.getElementById('e7921b12-5927-4af5-a39f-cd49b021efe1');
var x = new MutationObserver(function (mutations, observer) {{
        var display = window.getComputedStyle(gd).display;
        if (!display || display === 'none') {{
            console.log([gd, 'removed!']);
            Plotly.purge(gd);
            observer.disconnect();
        }}
}});

// Listen for the removal of the full notebook cells
var notebookContainer = gd.closest('#notebook-container');
if (notebookContainer) {{
    x.observe(notebookContainer, {childList: true});
}}

// Listen for the clearing of the current output cell
var outputEl = gd.closest('.output');
if (outputEl) {{
    x.observe(outputEl, {childList: true});
}}

                        })
                };
                });

@JanHomann
Copy link

I can click on any of them (where it's underlined) and share it here, if that helps any...

Screen Shot 2020-09-08 at 7 55 15 PM

@JanHomann
Copy link

In jupyter notebook it works. Same environment.

@nicolaskruchten
Copy link
Contributor

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 the jupyterlab-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!

@JanHomann
Copy link

JanHomann commented Sep 9, 2020

@nicolaskruchten believe it or not, but i managed to get it working on one of my environments. Though that one is a bit older than the other one.

jupyter --version
jupyter core     : 4.6.3
jupyter-notebook : 6.0.3
qtconsole        : 4.7.6
ipython          : 7.14.0
ipykernel        : 5.3.0
jupyter client   : 6.1.3
jupyter lab      : 2.2.6
nbconvert        : 5.6.1
ipywidgets       : 7.5.1
nbformat         : 5.0.6
traitlets        : 4.3.3
jupyter labextension list                           
JupyterLab v2.2.6
Known labextensions:
   app dir: /Users/...... path to environment...... /.venv/share/jupyter/lab
        jupyterlab-plotly v4.9.0  enabled  OK

@nicolaskruchten
Copy link
Contributor

OK nice! So... what's different about this environment? Do things break if you install the other labextensions? All the ones you had before were developed at Plotly or required by them (the manager) so I'd be surprised if they conflict with each other somehow but hey, if they do I know who to ask to get it fixed :)

@JanHomann
Copy link

JanHomann commented Sep 9, 2020

I installed two more extensions and it still works. Now i have interactive widget support =) That's what i was looking for.
I am kind of scared to install the other two, jupyterlab-chart-editor and jupyterlab-dash because they might break things. But the chart editor would be nice to have...

@jupyter-widgets/jupyterlab-manager v2.0.0  enabled  OK
jupyterlab-plotly v4.9.0  enabled  OK
plotlywidget v4.9.0  enabled  OK

@ahotrod
Copy link

ahotrod commented Sep 14, 2020

@nicolaskruchten

Same problem, fig = go.Figure() ... (fig.definitions) ... fig.show() doesn't render the plot in JupyterLab, works in Jupyter Notebook.

My installation:

- Platform: Linux-5.4.0-47-generic-x86_64-with-glibc2.10
- Python version: 3.8.1

$ node -v
v14.10.1

$  jupyter --version
jupyter core     : 4.6.3
jupyter-notebook : 6.1.1
qtconsole        : 4.7.6
ipython          : 7.18.1
ipykernel        : 5.3.4
jupyter client   : 6.1.6
jupyter lab      : 2.2.6
nbconvert        : 5.6.1
ipywidgets       : 7.5.1
nbformat         : 5.0.7
traitlets        : 4.3.3

plotly  4.10.0

~$ labextension list
JupyterLab v2.2.6
Known labextensions:
   app dir: /home/dn/anaconda3/envs/nlpu/share/jupyter/lab
        @jupyter-widgets/jupyterlab-manager v2.0.0  enabled  OK
        jupyterlab-plotly v4.10.0  enabled  OK
        plotlywidget v4.10.0  enabled  

jupyter lab build didn't help.

Update: Just noticed the JupyterLab extensions for plotly, installed from the command-line per plotly instructions, do not subsequently show-up in the "INSTALLED" section of the JupyterLab Extension Manager. Could that be the issue? I can't say presently. Will keep investigating.

2nd update: Got it working. I had an earlier JupyterLab version installed in my "base" environment, and the latest JupyterLab version and extensions in my working environment. I was starting JupyterLab from the base environment and not getting the latest version + extensions. All's well.

@Peterstangolis
Copy link

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 the jupyterlab-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!

  • fig.show("jupyterlab") <--- This worked for me. Thanks for the solve.

@bicepjai
Copy link

bicepjai commented Nov 17, 2020

sample blank image under the cell on jupyterlab

jupyter core     : 4.6.3
jupyter-notebook : 6.0.3
qtconsole        : not installed
ipython          : 7.13.0
ipykernel        : 5.1.4
jupyter client   : 6.0.0
jupyter lab      : 2.2.9
nbconvert        : 5.6.1
ipywidgets       : 7.5.1
nbformat         : 5.0.4
traitlets        : 4.3.3
JupyterLab v2.2.9
Known labextensions:
   app dir: <path>
        @jupyter-widgets/jupyterlab-manager v2.0.0  enabled  OK
        @jupyterlab/git v0.20.0  enabled  OK
        @jupyterlab/toc v4.0.0  enabled  OK
        jupyterlab-plotly v4.12.0  enabled  OK
        nbdime-jupyterlab v2.0.0  enabled  OK
        plotlywidget v4.12.0  enabled  OK

Uninstalled core extensions:
    @telamonian/theme-darcula
    jupyterlab-plotly

None of the above solutions worked

  1. using fig.show("jupyterlab")
  2. jupyter lab build
  3. enabling trusted notebook
  4. Default renderer is 'plotly_mimetype+notebook', changing to 'plotly_mimetype+jupyterlab' or 'plotly_mimetype', did not solve the issue

setting pio.renderers.default to iframe

@tg137
Copy link

tg137 commented Jan 4, 2021

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 running jupyter lab build) which can be done through the JupyterLab UI by doing the following:

  • In the left hand navbar click the search icon
  • Search for "Reset application state"
  • Click the first result
  • Wait for the page to refresh and retry building your plot

I've attached a GIF of this process for clarity:

reset-state

For reference, my lab extensions look like the following:

(base) jovyan@visualisation-plotly:~$ jupyter labextension list
JupyterLab v2.2.8
Known labextensions:
   app dir: /opt/conda/share/jupyter/lab
        @jupyter-widgets/jupyterlab-manager v2.0.0  enabled  OK
        jupyterlab-plotly v4.14.1  enabled  OK

And my method of actually rendering the plot is to use iplot:

from plotly.offline import download_plotlyjs, init_notebook_mode, iplot, plot

...

iplot(fig, validate=False)

@satomlins
Copy link

I'm having all the issues mentioned above, none of the solutions are working. Have tried setting up a fresh conda environment, have followed all the troubleshooting on the website and browsed a variety of github issues and stack overflow posts.

Guess I'll be heading back to notebooks having spent a few hours trying to sort this :(

@JanHomann
Copy link

I'm having all the issues mentioned above, none of the solutions are working. Have tried setting up a fresh conda environment, have followed all the troubleshooting on the website and browsed a variety of github issues and stack overflow posts.

Guess I'll be heading back to notebooks having spent a few hours trying to sort this :(

Have you tried the latest version of JupyterLab and plotly? I think i read somewhere that there was something fixed, but not sure.

@madpower2000
Copy link

I've got the same issue with latest version of Lab & Dash:
plotly/jupyter-dash#57

@derekhe
Copy link

derekhe commented Apr 25, 2021

I managed to make it work in jupyter lab using:

import plotly.io as pio
pio.renderers.default='iframe'

@deeppunj
Copy link

deeppunj commented Jul 25, 2021

I got it working by installing the "jupyterlab-plotly" extension.

In the anaconda command prompt:

jupyter labextension install jupyterlab-plotly

and then

jupyter lab build

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:

import plotly.graph_objects as go
fig = go.Figure(data=go.Bar(y=[2, 3, 1]))
fig.show()

I get the outupt in my jupyterlab notebook as:
image

@SBS-EREHM
Copy link

SBS-EREHM commented Aug 8, 2024

It's 2024 and this still doesn't work in JupyterHub 4. Same error -- that seems straightforward to me to for JupyterLab/Hub developers to fix: ReferenceError: require is not defined pointing to : require(["plotly"], function(Plotly) {.

And now labextensions are deprecated and/or disabled. I'll have to live with the iframe renderer for now, but iframe really wrecks the "live" notebook experience.

erehm@rnd-ubuntuVM:~$ jupyter --version
Selected Jupyter core packages...
IPython : 8.26.0
ipykernel : 6.29.5
ipywidgets : 8.1.3
jupyter_client : 8.6.2
jupyter_core : 5.7.2
jupyter_server : 2.14.2
jupyterlab : 4.2.4
nbclient : 0.10.0
nbconvert : 7.16.4
nbformat : 5.10.4
notebook : not installed
qtconsole : not installed
traitlets : 5.14.3

erehm@rnd-ubuntuVM:~$ jupyter labextension list
sys_prefix level settings are read-only, using user level for migration to lockedExtensions
JupyterLab v4.2.4
/opt/jupyterhub/share/jupyter/labextensions
jupyterlab_pygments v0.3.0 enabled OK (python, jupyterlab_pygments)
@jupyter-widgets/jupyterlab-manager v5.0.11 enabled OK (python, jupyterlab_widgets)

erehm@rnd-ubuntuVM:~$ jupyter labextension install jupyterlab-plotly
(Deprecated) Installing extensions with the jupyter labextension install command is now deprecated and will be removed in a future major version of JupyterLab.

Users should manage prebuilt extensions with package managers like pip and conda, and extension authors are encouraged to distribute their extensions as prebuilt packages
/opt/jupyterhub/lib/python3.12/site-packages/jupyterlab/debuglog.py:54: UserWarning: An error occurred.
warnings.warn("An error occurred.")
/opt/jupyterhub/lib/python3.12/site-packages/jupyterlab/debuglog.py:55: UserWarning: ValueError: Please install nodejs >=20.0.0 before continuing. nodejs may be installed using conda or directly from the nodejs website.
warnings.warn(msg[-1].strip())
/opt/jupyterhub/lib/python3.12/site-packages/jupyterlab/debuglog.py:56: UserWarning: See the log file for details: /tmp/jupyterlab-debug-e4ziss1y.log
warnings.warn(f"See the log file for details: {log_path!s}")

erehm@rnd-ubuntuVM:~$ conda install -c conda-forge -c plotly jupyterlab-plotly
Channels:

  • conda-forge
  • plotly
  • defaults
    Platform: linux-64
    Collecting package metadata (repodata.json): done
    Solving environment: failed

PackagesNotFoundError: The following packages are not available from current channels:

  • jupyterlab-plotly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests