Skip to content

6.0.0 release issue for Shiny for Python apps: "Please install anywidget to use the FigureWidget class" #4996

Closed

Description

@igi-chris

I am building a shiny for python dashboard. On the latest deployment plotly updated from 5.24.1 -> 6.0.0 and the plots no longer render with the error: "Please install anywidget to use the FigureWidget class". For now I have worked around the issue by specifying the version in my requirements.txt file plotly==5.24.1

Activity

  1. igi-chris commented on Jan 29, 2025

    @igi-chris
    Author

    For a reproducible example you can use one of the template apps provided by shiny that uses plotly e.g. the dashboard-tips template. Once you have shiny installed you can download the template with shiny create --template dashboard-tips --mode express --github posit-dev/py-shiny-templates, set up a virtual env and install the dependencies in the downloaded requirements.txt file.

    Using plotly 6.0.0 the plots fail as shown in the screenshot below:
    Image

    However, if you downgrade plotly to 5.24.1 the dashboard renders as expected:
    Image

    Here is the full traceback (from the 6.0.0 version):

    Traceback (most recent call last):
    File "d:\code\spikes\shiny_experiments.venv\Lib\site-packages\shiny\session_session.py", line 1450, in output_obs
    value = await renderer.render()
    ^^^^^^^^^^^^^^^^^^^^^^^
    File "d:\code\spikes\shiny_experiments.venv\Lib\site-packages\shinywidgets_render_widget_base.py", line 87, in render
    widget = as_widget(value)
    ^^^^^^^^^^^^^^^^
    File "d:\code\spikes\shiny_experiments.venv\Lib\site-packages\shinywidgets_as_widget.py", line 26, in as_widget
    res = _as_widget(x)
    ^^^^^^^^^^^^^
    File "d:\code\spikes\shiny_experiments.venv\Lib\site-packages\shinywidgets_as_widget.py", line 75, in as_widget_plotly
    return go.FigureWidget(x.data, x.layout) # type: ignore
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "d:\code\spikes\shiny_experiments.venv\Lib\site-packages\plotly\missing_anywidget.py", line 13, in init
    raise ImportError("Please install anywidget to use the FigureWidget class")
    ImportError: Please install anywidget to use the FigureWidget class

  2. ndrezn commented on Jan 29, 2025

    @ndrezn
    Contributor

    @marthacryan I see that anywidget is only in requires-optional: https://github.com/plotly/plotly.py/blob/master/packages/python/plotly/requires-optional.txt#L51 Should it go into a requires-jupyter or elsewhere so that it's easier to know what to install?

    This is a UX recommendation; the fix for this issue @igi-chris might be for Posit to update their templates.

    You can also:

    pip install anywidget
    

    manually in your environment to resolve the issue.

  3. marthacryan commented on Jan 29, 2025

    @marthacryan
    Contributor

    I agree! One thing I'll note though is that this is identical to the behavior before the 6.0.0 release except that ipywidgets was substituted for anywidget as the package required. We should at the very least update the wording of the error to say pip install anywidget for clarity.

  4. added
    bugsomething broken
    P1needed for current cycle
    on Feb 3, 2025
  5. turbotimon commented on Feb 11, 2025

    @turbotimon

    Please also note this line from the v6.0 release notes (it was the reason why my code failed even with anywidget manually installed):

    Fix go.FigureWidget.show to return FigureWidget instead of displaying Figure [https://github.com//pull/4869]

    Edit: No, I'm still now able to get FigureWidget to work in v6.0.0. Only downgrading solves the problem: #5027

  6. gvwilson commented on Jun 17, 2025

    @gvwilson
    Contributor

    @turbotimon apologies for the slow response - when you say "still now able to get FigureWidget to work with v6.0.0" do you mean "still not able"? thanks - @gvwilson

  7. turbotimon commented on Jun 18, 2025

    @turbotimon

    @gvwilson sorry for the unclear wording. Yes, I meant "still not able". However, I just retried my test example with plotly==6.1.2 anywidget==0.9.18 and it seems to work fine now👍 (There is still a strange behavior in colab tough, but it works in vscode notebooks #5027 (comment))

  8. removed their assignment
    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

    P1needed for current cyclebugsomething brokendocumentationwritten for humans

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions