Repository navigation
FigureWidget fails with anywidget in colab #5027
Copy link
Copy link
Open
Labels
Description
Problem:
Since v6.0.0 FigureWidget uses anywidget. However, it fails with a java script error.
$ pip show plotly anywidget
Name: plotly
Version: 6.0.0
Summary: An open-source, interactive data visualization library for Python
Home-page: https://plotly.com/python/
Author: Chris P
Author-email: chris@plot.ly
License: MIT
Location: /home/erti/PROJECT_repos/ForeST_HPO/hpo-innosuisse/.venv_anywidget/lib/python3.11/site-packages
Requires: narwhals, packaging
Required-by:
---
Name: anywidget
Version: 0.9.13
Summary: custom jupyter widgets made easy
Home-page:
Author:
Author-email: Trevor Manz <trevor.j.manz@gmail.com>
License: MIT
Location: /home/erti/PROJECT_repos/ForeST_HPO/hpo-innosuisse/.venv_anywidget/lib/python3.11/site-packages
Requires: ipywidgets, psygnal, typing-extensions
Required-by: import plotly.graph_objs as go
fig = go.FigureWidget()
fig.add_scatter(y=[2, 1, 4, 3])
figEither, no output (no figure) is shown or this is shown:
Failed to load view class 'AnyView' from module 'anywidget'
Error: No version of module anywidget is registered
at WidgetManager.loadClass (https://file+.vscode-resource.vscode-cdn.net/home/erti/.vscode/extensions/ms-toolsai.jupyter-renderers-1.1.0/out/node_modules/%40vscode/jupyter-ipywidgets8/dist/ipywidgets.js:2:2420023)
at WidgetManager.loadClass (https://file+.vscode-resource.vscode-cdn.net/home/erti/.vscode/extensions/ms-toolsai.jupyter-renderers-1.1.0/out/node_modules/%40vscode/jupyter-ipywidgets8/dist/ipywidgets.js:2:2803837)
at WidgetManager.loadViewClass (https://file+.vscode-resource.vscode-cdn.net/home/erti/.vscode/extensions/ms-toolsai.jupyter-renderers-1.1.0/out/node_modules/%40vscode/jupyter-ipywidgets8/dist/ipywidgets.js:2:2417001)
at https://file+.vscode-resource.vscode-cdn.net/home/erti/.vscode/extensions/ms-toolsai.jupyter-renderers-1.1.0/out/node_modules/%40vscode/jupyter-ipywidgets8/dist/ipywidgets.js:2:2410155
at async Tt.renderWidget (https://file+.vscode-resource.vscode-cdn.net/home/erti/.vscode/extensions/ms-toolsai.jupyter-2024.11.0-linux-x64/dist/webviews/webview-side/ipywidgetsKernel/ipywidgetsKernel.js:17:17328)
at async op (https://file+.vscode-resource.vscode-cdn.net/home/erti/.vscode/extensions/ms-toolsai.jupyter-2024.11.0-linux-x64/dist/webviews/webview-side/ipywidgetsKernel/ipywidgetsKernel.js:17:31113)Workaround:
Downgrading to plotly-5.24 solves the problem
Related:
Maybe somewhat related to #4996
Reactions are currently unavailable
Activity
[-]`FigureWidget` fails with `anywidget` in v6.0.0[/-][+][BUG] `FigureWidget` fails with `anywidget` in v6.0.0[/+][-][BUG] `FigureWidget` fails with `anywidget` in v6.0.0[/-][+]`FigureWidget` fails with `anywidget` in v6.0.0[/+]marthacryan commentedon Feb 11, 2025
Could you describe the way that you installed anywidget? I was seeing this issue when I installed anywidget while JupyterLab was running without restarting it. I'm curious if restarting JupyterLab / reloading the page would help. (Still a bug, just good info for debugging)
turbotimon commentedon Feb 12, 2025
@marthacryan I created a fresh venv with python3.11 and run
pip install plotly anywidgetand run the code in vscode notebook. I also restarted the kernel several times, somties just no output is shown, somtimes the json error. I also tried to run it in google colab. There, I don't see the json error, but also get no output (the figure is not shown).marthacryan commentedon Feb 13, 2025
Thank you for the info @turbotimon! Looks like this is an issue with
plotly.js==3.0.0, which we updated to for theplotly.py==6.0.0release. I'll investigate why this is happening but as a note, I think it may be related to removing require.js and needing to update the way that we includeplotly.js.marthacryan commentedon Feb 14, 2025
Update here: looks like there is a PR open that does fix this issue for plotly.js: plotly/plotly.js#7367.
marthacryan commentedon Feb 18, 2025
Plotly.js just released the 3.0.1 patch which will fix this! We'll need to update the plotly.js version in plotly.py, so I'll wait on that to close this issue.
ershov commentedon Mar 20, 2025
Hi,
I'm having this issue too. Could any one suggest how to I apply patch to my existing installation of plotly in Python?
afeld commentedon Mar 20, 2025
You can't upgrade?
turbotimon commentedon Mar 20, 2025
Upgrade or downgrade, just don't use v6.0.0, e.g.:
pip install plotly!=6.0.0marthacryan commentedon Mar 20, 2025
@turbotimon Is this now working for you?
turbotimon commentedon Mar 20, 2025
With 5.24 it is, I did not try it with 6.0.1 yet..
Edit: Just tried with 6.0.1 in colab. It works but behaves different, a single
figorfig.show()at the end of the cell won't show the plot (as it did in 5.24), but adisplay(fig)will. @marthacryan is this a "feature or a bug" and is this due to your #4869?Test code:
Edit2: It seems that this behaviour is only in colab. But it seems to work in e.g. vscode notebooks. I did not try it in jupyter lab. Versions used
plotly==6.1.2 anywidget==0.9.18marthacryan commentedon Jun 18, 2025
Oh interesting @turbotimon I'm seeing the same behavior in colab. This must be a difference in how they handle displaying widgets. I think for now using the
displayfunction in colab seems like a good workaround.[-]`FigureWidget` fails with `anywidget` in v6.0.0[/-][+]`FigureWidget` fails with `anywidget` in colab[/+]