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

ipywidgets 7.7.4 breaks shinywidgets #79

Closed
bartverweire opened this issue Mar 23, 2023 · 2 comments · Fixed by #80
Closed

ipywidgets 7.7.4 breaks shinywidgets #79

bartverweire opened this issue Mar 23, 2023 · 2 comments · Fixed by #80

Comments

@bartverweire
Copy link

  • shinywidgets version: 0.1.15
  • shiny version : 0.2.10
  • Python version: 3.10.2
  • Operating System: Windows
  • ipywidgets version: 7.7.4

Description

Trying to display a plotly output widget.
When using ipywidgets 7.7.4, this fails with

Traceback (most recent call last):
  File "C:\Tools\Anaconda3\envs\python_310\lib\site-packages\shiny\session\_session.py", line 1017, in output_obs
    message[output_name] = fn()
  File "C:\Tools\Anaconda3\envs\python_310\lib\site-packages\shinywidgets\_shinywidgets.py", line 168, in __call__
    return run_coro_sync(self.run())
  File "C:\Tools\Anaconda3\envs\python_310\lib\site-packages\shiny\_utils.py", line 218, in run_coro_sync
    coro.send(None)
  File "C:\Tools\Anaconda3\envs\python_310\lib\site-packages\shinywidgets\_shinywidgets.py", line 171, in run
    x = await self._fn()
  File "C:\Tools\Anaconda3\envs\python_310\lib\site-packages\shiny\_utils.py", line 173, in fn_async
    return fn()
  File "C:\Workspace\Python\Shiny\Clean\app.py", line 26, in plot
    fig = go.FigureWidget(fig)
  File "C:\Tools\Anaconda3\envs\python_310\lib\site-packages\plotly\graph_objs\_figurewidget.py", line 629, in __init__
    super(FigureWidget, self).__init__(data, layout, frames, skip_invalid, **kwargs)
  File "C:\Tools\Anaconda3\envs\python_310\lib\site-packages\plotly\basewidget.py", line 117, in __init__
    super(BaseFigureWidget, self).__init__(
  File "C:\Tools\Anaconda3\envs\python_310\lib\site-packages\plotly\basedatatypes.py", line 461, in __init__
    super(BaseFigure, self).__init__()
  File "C:\Tools\Anaconda3\envs\python_310\lib\site-packages\ipywidgets\widgets\widget.py", line 479, in __init__
    Widget._call_widget_constructed(self)
  File "C:\Tools\Anaconda3\envs\python_310\lib\site-packages\ipywidgets\widgets\widget.py", line 338, in _call_widget_constructed
    Widget._widget_construction_callback(widget)
  File "C:\Tools\Anaconda3\envs\python_310\lib\site-packages\shinywidgets\_shinywidgets.py", line 74, in init_shiny_widget
    old_comm_klass = copy.copy(Widget.comm.klass)  # type: ignore
AttributeError: 'Any' object has no attribute 'klass'

What I Did

Here's a simple app demonstrating the issue

from shiny import App, render, ui
from shinywidgets import *
import pandas as pd

import plotly.express as px
import plotly.graph_objects as go

df = pd.DataFrame({"x": [1, 2, 3], "y": [2, 0.5, 1], "z": [1, 1, 1]}, index=[0, 1, 2])


app_ui = ui.page_fluid(
    ui.h2("Hello Plotly!"),
    output_widget("plot")
)


def server(input, output, session):
    @output
    @render_widget
    def plot():
        fig = px.bar(df, x="x", y="y", color="z",
                     orientation="v",
                     height=400
                     )

        return go.FigureWidget(fig)


app = App(app_ui, server)

then run

shiny run --reload app.py

The issue disappears when switching back to ipywidgets==7.7.3.

Kind Regards

Bart

@cpsievert
Copy link
Collaborator

cpsievert commented Mar 23, 2023

Are you sure 7.7.4 introduced this failure? It looks like the 8.0.5 (released yesterday) introduced it.

cpsievert added a commit that referenced this issue Mar 23, 2023
…()` (#80)

* Close #79: ipywidgets' Widget.comm field now uses Any() instead of Instance()

* Avoid having to import traitlets
@bartverweire
Copy link
Author

Yes, I'm sure that this occurs with 7.7.4 :

...
AttributeError: 'Any' object has no attribute 'klass'
INFO:     Shutting down
INFO:     connection closed
INFO:     Waiting for application shutdown.
INFO:     Application shutdown complete.
INFO:     Finished server process [3632]
INFO:     Stopping reloader process [9656]
(venv) PS C:\Workspace\Python\Shiny\Clean> ^C
(venv) PS C:\Workspace\Python\Shiny\Clean> pip show ipywidgets
Name: ipywidgets
Version: 7.7.4
Summary: IPython HTML widgets for Jupyter

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants