-1

I have those versions installed:

# I downgraded to 4.0.3 but same error
jupyter-lab --version
4.0.5

Name: plotly
Version: 5.15.0

this is the sample code. it plots on vscode but it does not run on jupyter-lab

import chart_studio.plotly as py
import plotly.graph_objs as go
import plotly.express as px

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

# this is needed in jupyter
init_notebook_mode(connected=True)

px.box(x=[1,2,3,4] , y=[1,4,9,16] )

plotly requires a browser environment to run. I googled the plotly-jupyter issue and none of the solutions worked. I tried with jupyter notebook as well but it did not work. So I open Chrome console (I tried on firefox but same error)to dive into the problem. every time I execute the plotting code, I get this error:

  Uncaught ReferenceError: require is not defined

enter image description here

this is the source of error:

enter image description here

I think somehow plotly uses javascript but it has no access to javascript. I disabled all the extensions, restart the kernel but still same error

However, I'm stuck at this point, and I'm not sure how to go further. Can someone please provide guidance on how to proceed from here?

those are installed plugins:

enter image description here

Yilmaz
  • 35,338
  • 10
  • 157
  • 202
  • Your code works in JupyterLab 3.4.8. So it is probably a bad environment / bad install among the involved packages. You don't say whether simpler Plotly plots from the many examples in the documentation work? Or if this worked in older JupyterLab for you. For comparison, you can see it working in 3.4.8 without touching your system by going [here](https://github.com/fomightez/3Dscatter_plot-binder) and clicking 'launch binder'. When the temporary session loads up, open a new notebook and run `%pip install chart-studio`. Restart the kernel and then run your code. I'll try JupyterLab 4 if I can. – Wayne Sep 02 '23 at 14:26
  • JupyterLab 4.0.3 works, too. (It would take too long to build an example with Jupyter 4.0.5 right now.) You can try it for comparison by going [here](https://gist.github.com/fomightez/e6f5ec9703c87aabd4b25d26b67e4e35) and clicking the bottom '`launch binder`' badge. When the session starts, start a new notebook. When the new notebook opens run `%pip install chart-studio` and then `%pip install pandas`. Restart the kernel and run your code. – Wayne Sep 02 '23 at 14:43
  • On your system, did you try adding [the two lines suggested here](https://github.com/plotly/plotly_express/issues/38#issuecomment-826602624) near the top of your code? (That same suggestion gets suggested [here](https://github.com/plotly/plotly.py/issues/2672#issuecomment-826271731) in reply to this long thread with other things to try [here](https://github.com/plotly/plotly.py/issues/2672). The rest of that thread has several other things to try.) Maybe try it in a new notebook (or restart the kernel) without the line `init_notebook_mode(connected=True)`? – Wayne Sep 02 '23 at 15:27
  • Which extension did you install? See [here](https://stackoverflow.com/a/58317897/8508004). Also, are you sure you are using up-to-date example code. I'm not seeing anything like you use at https://plotly.com/python/ . In fact, the information under the section 'Offline features (plotly.offline) replaced by Renderers framework & HTML export' on [the page 'Version 4 Migration Guide in Python'](https://plotly.com/python/v4-migration/) makes me think part of your issue is you are using old code/approaches with modern tech. Plotly & JupyterLab both have evolved a lot lately. Use current examples. – Wayne Sep 02 '23 at 15:35
  • @Wayne thank you for your help. I posted the image of the installed plugins. I did also placed the 2 lines of code on top and still not showing and same error on the console. If I could figure out why i get `require(["plotly"], function(Plotly) ` i might solve the problem but I don t know what is the causing the issue. I also tried with disabling all the extensions, restart the kernel but still same – Yilmaz Sep 02 '23 at 15:39
  • @Wayne regarding the code example, I just created it for testing purpose. I encountered the issue with one of my projects, so I created a sample code above and that code works on vscode if I run it with `Run Current File in Interactive Window`. – Yilmaz Sep 02 '23 at 15:48
  • @Wayne I uninstalled 4.0.5 and installed 4.0.3 but same error – Yilmaz Sep 02 '23 at 16:03
  • Sorry, I didn't mean to imply that 4.0.3 would be any better. It was just the version of JupyterLab 4.0 I had access to. Okay you created the present code as a toy example; however, it doesn't match current examples in the Plotly documentation. The extensions you list don't mention Plotly unless I am missing something? – Wayne Sep 02 '23 at 16:59
  • @wayne this is plotly docs for jupyterlab support: https://plotly.com/python/getting-started/ you can see that it's example similar to mine. I installed all the extensions mentioned here. i think the issue is `plotly` uses `javascript` somehow and it has no access to it – Yilmaz Sep 02 '23 at 19:40
  • On that page https://plotly.com/python/getting-started/ there are no examples that use **any of these**: `chart_studio.plotly` , `init_notebook_mode(connected=True)`, `download_plotlyjs` `iplot`, `plotly.graph_objs as go`, `plotly.offline`. I know the code works where I pointed and so that isn't a huge issue. However, it is concerning because perhaps it is complicating an issue you are already having. I do note that the documentation there also states "The instructions above apply to JupyterLab 3.x. " Nothing about JupyterLab 4. – Wayne Sep 02 '23 at 20:42
  • Had Plotly been working in your JupyterLab before? Had you updated recently? Had it worked in Jupyter notebook document centric interface, the more classic interface on your system before? Or is this an all new installation of JupyterLab you are trying this on now? Have you tried installing [the Anaconda Distribution](https://docs.anaconda.com/free/anaconda/index.html) and tried JupyterLab and Plotly there? – Wayne Sep 02 '23 at 20:47

0 Answers0