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

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

Open
igi-chris opened this issue Jan 29, 2025 · 4 comments
Assignees
Labels
bug something broken documentation written for humans P1 needed for current cycle

Comments

@igi-chris
Copy link

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

@igi-chris
Copy link
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

@ndrezn
Copy link
Member

ndrezn commented Jan 29, 2025

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

@marthacryan
Copy link
Collaborator

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.

@gvwilson gvwilson added bug something broken P1 needed for current cycle documentation written for humans labels Feb 3, 2025
@turbotimon
Copy link

turbotimon commented Feb 11, 2025

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug something broken documentation written for humans P1 needed for current cycle
Projects
None yet
Development

No branches or pull requests

5 participants