Skip to content

Incompatible FigureWidget with ipywidgets 8.0.0rc0 #3686

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

Closed
JP-Ellis opened this issue Apr 22, 2022 · 15 comments · Fixed by ml-struct-bio/cryodrgn#138
Closed

Incompatible FigureWidget with ipywidgets 8.0.0rc0 #3686

JP-Ellis opened this issue Apr 22, 2022 · 15 comments · Fixed by ml-struct-bio/cryodrgn#138

Comments

@JP-Ellis
Copy link
Contributor

Plotly's FigureWidget does not appear to be compatible with the upcoming ipywidgets release.

python -m venv .venv
. ./.venv/bin/activate
pip install plotly jupyterlab ipywidgets==8.0.0rc0
jupyer-lab

If using directly the FigureWidget as the output of the cell, the figure is shown by with the following error:

import plotly.graph_objects as go

go.FigureWidget(go.Scatter(x=[1, 2, 3], y=[1, 4, 9]))
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
File /tmp/josh/bug-report/.venv/lib/python3.10/site-packages/IPython/core/formatters.py:921, in IPythonDisplayFormatter.__call__(self, obj)
    919 method = get_real_method(obj, self.print_method)
    920 if method is not None:
--> 921     method()
    922     return True

File /tmp/josh/bug-report/.venv/lib/python3.10/site-packages/plotly/basewidget.py:741, in BaseFigureWidget._ipython_display_(self)
    737 """
    738 Handle rich display of figures in ipython contexts
    739 """
    740 # Override BaseFigure's display to make sure we display the widget version
--> 741 widgets.DOMWidget._ipython_display_(self)

AttributeError: type object 'DOMWidget' has no attribute '_ipython_display_'

On the other hand, if the FigureWidget is used within other widgets, the figure does not appear at all (though there isn't any error message):

import plotly.graph_objects as go
from ipywidgets import widgets

widgets.VBox([
    widgets.HTML("<p>Start</p>"),
    go.FigureWidget(go.Scatter(x=[1, 2, 3], y=[1, 4, 9])),
    widgets.HTML("<p>End</p>"),
])

image

This was generated using Plotly 5.7.0 and ipywidgets 8.0.0rc0 all within JupyterLab 3.3.4.

@fabratu
Copy link

fabratu commented Aug 19, 2022

The same error occurs for plotly 5.8.0 and 5.9.0.

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
File ~/miniforge3/envs/nwk10/lib/python3.10/site-packages/IPython/core/formatters.py:921, in IPythonDisplayFormatter.__call__(self, obj)
    919 method = get_real_method(obj, self.print_method)
    920 if method is not None:
--> 921     method()
    922     return True

File ~/miniforge3/envs/nwk10/lib/python3.10/site-packages/plotly/basewidget.py:741, in BaseFigureWidget._ipython_display_(self)
    737 """
    738 Handle rich display of figures in ipython contexts
    739 """
    740 # Override BaseFigure's display to make sure we display the widget version
--> 741 widgets.DOMWidget._ipython_display_(self)

AttributeError: type object 'DOMWidget' has no attribute '_ipython_display_'

Together with jupyterlab, it is also not so clear how to resolve it. Installing ipywidgets<8.X is not automatically registered with jupyterlab 3.4.X (leading to a blank output).

Error: Module @jupyter-widgets/base, version ^1.2.0 is not registered, however,         2.0.0 is
    loadClass http://localhost:8888/lab/extensions/@jupyter-widgets/jupyterlab-manager/static/134.c8db098d38011369cafa.js?v=c8db098d38011369cafa:1
    loadModelClass http://localhost:8888/lab/extensions/@jupyter-widgets/jupyterlab-manager/static/150.a4d4bb4ed1bc1a3626c7.js?v=a4d4bb4ed1bc1a3626c7:1
    _make_model http://localhost:8888/lab/extensions/@jupyter-widgets/jupyterlab-manager/static/150.a4d4bb4ed1bc1a3626c7.js?v=a4d4bb4ed1bc1a3626c7:1
    new_model http://localhost:8888/lab/extensions/@jupyter-widgets/jupyterlab-manager/static/150.a4d4bb4ed1bc1a3626c7.js?v=a4d4bb4ed1bc1a3626c7:1
    handle_comm_open http://localhost:8888/lab/extensions/@jupyter-widgets/jupyterlab-manager/static/150.a4d4bb4ed1bc1a3626c7.js?v=a4d4bb4ed1bc1a3626c7:1
    _handleCommOpen http://localhost:8888/lab/extensions/@jupyter-widgets/jupyterlab-manager/static/134.c8db098d38011369cafa.js?v=c8db098d38011369cafa:1
    _handleCommOpen http://localhost:8888/static/lab/jlab_core.081dc2b13065c79d8463.js?v=081dc2b13065c79d8463:2

Update: Solved at least jupyterlab + prev. ipywidgets versions by installing package jupyterlab-widgets in version 1.1.1:

pip install ipywidgets==7.7.1 jupyterlab-widgets==1.1.1

@darynwhite
Copy link

This is come into production and is causing a problem with a live environment, but I have found this reference as a fix:
jupyter-widgets/ipywidgets#3552 (comment)

@mathcodemaster
Copy link

mathcodemaster commented Sep 14, 2022

@mathcodemaster
Copy link

Hello, i have a general question to the bug report process, (cause i am quite new to this).
How do we know that someone has recognized this as an issue to fix? i am asking because i would like to know if i can hope for a fix or if i have to find some other way,
best regards

@nicolaskruchten
Copy link
Contributor

This is an issue, yes, ipywidgets 8 just came out and we've not yet upgraded plotly to work with it. It's not so much a bug as an incompatibility because ipywidgets changed things between 7 and 8.

No one is currently actively working on changing plotly to be compatible with 8 and backwards-compatible with 7 etc, but we'd sure appreciate some help or pull requests if anyone from the community wants to step up and make this happen :)

facebook-github-bot pushed a commit to facebook/Ax that referenced this issue Nov 21, 2022
Summary:
Context:

Interactive figures on the website have not been displaying properly:

![image](https://user-images.githubusercontent.com/9137425/203114657-fb06925d-d798-483f-9be6-c300357cf955.png)

This happens because the newest version of Plotly is not compatible with the newest version if its dependency ipywidgets, which is needed for interactive figures: plotly/plotly.py#3686

So we can fix this by specifying the ipywidgets version.

Pull Request resolved: #1273

Test Plan:
- Reproduced the error with latest Ax + latest boTorch on my Mac
- Then it went away when I re-built with the specified ipywidgets version

Reviewed By: bernardbeckerman

Differential Revision: D41438932

Pulled By: esantorella

fbshipit-source-id: f6b2f430da1483a4613dac8f81a76dbc6f6dd4cb
@bingzhux
Copy link

The same issue here,

widgets.VBox([dropdownwdgt), figwdget])

this code above only displays the dropdown widget (dropdownwdgt), but doesn't show the figwdget (figure widget).

My versions:

jupyter-lab -> 3.5.0
plotly -> 5.9.0
ipywidgets -> 8.0.2
jupyterlab-widgets -> 3.0.3

how to fix or workaround this?

@gioxc88
Copy link

gioxc88 commented Nov 29, 2022

same issue

@cganuza
Copy link

cganuza commented Nov 29, 2022

For me installing the following versions worked:

  • jupyterlab-pygments==0.1.2
  • ipywidgets==7.6.5
  • jupyterlab-widgets==1.0.2
  • jupyterlab==3.2.4

@bingzhux
Copy link

bingzhux commented Nov 30, 2022

great... @cganuza , thank you ... after downgrade ipywidgets to 7.x from 8.x, it works for me too.

For me installing the following versions worked:

  • jupyterlab-pygments==0.1.2
  • ipywidgets==7.6.5
  • jupyterlab-widgets==1.0.2
  • jupyterlab==3.2.4

@cganuza
Copy link

cganuza commented Nov 30, 2022

For me installing the following versions worked:

* jupyterlab-pygments==0.1.2

* ipywidgets==7.6.5

* jupyterlab-widgets==1.0.2

* jupyterlab==3.2.4

I must add:

  • nbconvet==6.3.0
  • jupyter-server==1.12.1

@pmarcellino
Copy link

Is this issue a duplicate of #3930? They seem very similar to me.

@maresb
Copy link
Contributor

maresb commented Dec 8, 2022

@pmarcellino, #3930 is a PR targeting this issue, so not a duplicate.

@maresb
Copy link
Contributor

maresb commented Jan 14, 2023

@nicolaskruchten, based on the release notes, I believe this is closed by the latest release V5.12.0.

@nicolaskruchten
Copy link
Contributor

Yes, thanks for the reminder :)

@ebw44
Copy link

ebw44 commented Jan 30, 2023

In case you are using nb_conda_kernels, you also need plotly>=5.12.0 in the environment where you start the kernel.

facebook-github-bot pushed a commit to facebook/Ax that referenced this issue Feb 24, 2023
Summary:
#1273 set a maximum ipywidgets version since the then-most-recent version of Plotly wasn't compatible with the most current version. This is no longer necessary as of Plotly >=5.12.0.

Pull Request resolved: #1455

Test Plan:
Built the environment locally and ran code in a notebook that would have produced an error with incompatible plotly and ipywidgets versions, following [this issue](plotly/plotly.py#3686):

```python
import plotly.graph_objects as go

go.FigureWidget(go.Scatter(x=[1, 2, 3], y=[1, 4, 9]))
```

Reviewed By: mpolson64

Differential Revision: D43580470

Pulled By: esantorella

fbshipit-source-id: 644e8961a71c13758077ba590c07729a3c860010
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.