Skip to content

FigureWidget fails with anywidget in colab #5027

Open

Description

@turbotimon

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])
fig

Either, 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

Activity

  1. changed the title [-]`FigureWidget` fails with `anywidget` in v6.0.0[/-] [+][BUG] `FigureWidget` fails with `anywidget` in v6.0.0[/+] on Feb 11, 2025
  2. added
    bugsomething broken
    P1needed for current cycle
    on Feb 11, 2025
  3. changed the title [-][BUG] `FigureWidget` fails with `anywidget` in v6.0.0[/-] [+]`FigureWidget` fails with `anywidget` in v6.0.0[/+] on Feb 11, 2025
  4. marthacryan commented on Feb 11, 2025

    @marthacryan
    Contributor

    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)

  5. turbotimon commented on Feb 12, 2025

    @turbotimon
    Author

    @marthacryan I created a fresh venv with python3.11 and run pip install plotly anywidget and 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).

  6. marthacryan commented on Feb 13, 2025

    @marthacryan
    Contributor

    Thank you for the info @turbotimon! Looks like this is an issue with plotly.js==3.0.0, which we updated to for the plotly.py==6.0.0 release. 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 include plotly.js.

  7. marthacryan commented on Feb 14, 2025

    @marthacryan
    Contributor

    Update here: looks like there is a PR open that does fix this issue for plotly.js: plotly/plotly.js#7367.

  8. marthacryan commented on Feb 18, 2025

    @marthacryan
    Contributor

    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.

  9. ershov commented on Mar 20, 2025

    @ershov

    Hi,
    I'm having this issue too. Could any one suggest how to I apply patch to my existing installation of plotly in Python?

  10. afeld commented on Mar 20, 2025

    @afeld
    Contributor

    You can't upgrade?

  11. turbotimon commented on Mar 20, 2025

    @turbotimon
    Author

    Hi, I'm having this issue too. Could any one suggest how to I apply patch to my existing installation of plotly in Python?

    Upgrade or downgrade, just don't use v6.0.0, e.g.: pip install plotly!=6.0.0

  12. marthacryan commented on Mar 20, 2025

    @marthacryan
    Contributor

    @turbotimon Is this now working for you?

  13. turbotimon commented on Mar 20, 2025

    @turbotimon
    Author

    @turbotimon Is this now working for you?

    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 fig or fig.show() at the end of the cell won't show the plot (as it did in 5.24), but a display(fig) will. @marthacryan is this a "feature or a bug" and is this due to your #4869?

    Test code:

    # %%
    !pip install -U plotly anywidget
    # %%
    import plotly.graph_objs as go
    fig = go.FigureWidget()
    fig.add_scatter(y=[2, 1, 4, 3])
    fig # does not show anything!
    # %%
    display(fig) # but this
    # %%
    from ipywidgets import widgets
    button = widgets.Button(description="foo")
    
    def on_button_clicked(b):
        fig.data[0].y = [1, 2, 3, 4]
    
    button.on_click(on_button_clicked)
    button # test the change

    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.18

  14. added
    P2considered for next cycle
    and removed
    P1needed for current cycle
    on Jun 17, 2025
  15. marthacryan commented on Jun 18, 2025

    @marthacryan
    Contributor

    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 display function in colab seems like a good workaround.

  16. removed their assignment
    on Jun 18, 2025
  17. changed the title [-]`FigureWidget` fails with `anywidget` in v6.0.0[/-] [+]`FigureWidget` fails with `anywidget` in colab[/+] on Jun 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2considered for next cyclebugsomething broken

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions