plotly.py icon indicating copy to clipboard operation
plotly.py copied to clipboard

Incompatible FigureWidget with ipywidgets 8.0.0rc0

Open JP-Ellis opened this issue 3 years ago • 5 comments
trafficstars

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.

JP-Ellis avatar Apr 22 '22 04:04 JP-Ellis

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

fabratu avatar Aug 19 '22 13:08 fabratu

This is come into production and is causing a problem with a live environment, but I have found this reference as a fix: https://github.com/jupyter-widgets/ipywidgets/issues/3552#issuecomment-1220997361

darynwhite avatar Aug 23 '22 05:08 darynwhite

Same Problem with ipywidgets == 8.0.2 juoyter_lab_widgets == 3.0.3 plotly == 5.10.0

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

doesnt help in my case because i use vboxes which causes the following error then

[Open Browser Console for more detailed log - Double click to close this message] Failed to load model class 'VBoxModel' from module '@jupyter-widgets/controls' loadClass@http://localhost:8888/lab/extensions/@jupyter-widgets/jupyterlab-manager/static/134.bcbea9feb6e7c4da7530.js?v=bcbea9feb6e7c4da7530:1:74977 loadModelClass@http://localhost:8888/lab/extensions/@jupyter-widgets/jupyterlab-manager/static/150.3e1e5adfd821b9b96340.js?v=3e1e5adfd821b9b96340:1:10729 _make_model@http://localhost:8888/lab/extensions/@jupyter-widgets/jupyterlab-manager/static/150.3e1e5adfd821b9b96340.js?v=3e1e5adfd821b9b96340:1:7517 new_model@http://localhost:8888/lab/extensions/@jupyter-widgets/jupyterlab-manager/static/150.3e1e5adfd821b9b96340.js?v=3e1e5adfd821b9b96340:1:5137 handle_comm_open@http://localhost:8888/lab/extensions/@jupyter-widgets/jupyterlab-manager/static/150.3e1e5adfd821b9b96340.js?v=3e1e5adfd821b9b96340:1:3894 134/v/this._handleCommOpen@http://localhost:8888/lab/extensions/@jupyter-widgets/jupyterlab-manager/static/134.bcbea9feb6e7c4da7530.js?v=bcbea9feb6e7c4da7530:1:73393 _handleCommOpen@http://localhost:8888/static/lab/jlab_core.d6bc082464b66ab0e79a.js?v=d6bc082464b66ab0e79a:2:994480

mathcodemaster avatar Sep 14 '22 08:09 mathcodemaster

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

mathcodemaster avatar Sep 16 '22 06:09 mathcodemaster

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 :)

nicolaskruchten avatar Sep 16 '22 15:09 nicolaskruchten

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?

bingzhux avatar Nov 24 '22 02:11 bingzhux

same issue

gioxc88 avatar Nov 29 '22 08:11 gioxc88

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 avatar Nov 29 '22 16:11 cganuza

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

bingzhux avatar Nov 30 '22 01:11 bingzhux

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

cganuza avatar Nov 30 '22 19:11 cganuza

Is this issue a duplicate of https://github.com/plotly/plotly.py/pull/3930? They seem very similar to me.

pmarcellino avatar Dec 08 '22 01:12 pmarcellino

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

maresb avatar Dec 08 '22 10:12 maresb

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

maresb avatar Jan 14 '23 15:01 maresb

Yes, thanks for the reminder :)

nicolaskruchten avatar Jan 14 '23 15:01 nicolaskruchten

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

ebw44 avatar Jan 30 '23 21:01 ebw44