plotly.py: Incompatible FigureWidget with ipywidgets 8.0.0rc0
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>"),
])
This was generated using Plotly 5.7.0
and ipywidgets 8.0.0rc0
all within JupyterLab 3.3.4
.
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 15
- Comments: 15 (4 by maintainers)
Commits related to this issue
- Fix interactive Plotly figures by specifying ipywidgets version (#1273) Summary: Context: Interactive figures on the website have not been displaying properly:  Summary: https://github.com/facebook/Ax/pull/1273 set a maximum ipywidgets version since the then-most-recent version of Plotly wasn't compatible with th... — committed to facebook/Ax by esantorella a year ago
The same error occurs for plotly
5.8.0
and5.9.0
.Together with jupyterlab, it is also not so clear how to resolve it. Installing
ipywidgets<8.X
is not automatically registered with jupyterlab3.4.X
(leading to a blank output).Update: Solved at least jupyterlab + prev. ipywidgets versions by installing package jupyterlab-widgets in version 1.1.1:
great… @cganuza , thank you … after downgrade ipywidgets to 7.x from 8.x, it works for me too.
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