Skip to content

Using iplot with ipython.display duplicates widgets in JupyterLab #1516

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
manycoding opened this issue Apr 11, 2019 · 3 comments
Closed

Using iplot with ipython.display duplicates widgets in JupyterLab #1516

manycoding opened this issue Apr 11, 2019 · 3 comments

Comments

@manycoding
Copy link

I created the same issue for ipywidgets jupyter-widgets/ipywidgets#2359 because I am not sure where it belongs.

TL;DR If I plot a graph with plotly iplot, any ipywidgets are duplicated.

The reason why I don't use display() and widgets for both is that widgets are not saved if I close a notebook, and I want the graph output to be available after I reopen a notebook.
So I thought I can plot graphs with plotly.offline.iplot() and widgets with display(), but the former prints any available widget again and again.

import ipywidgets
import plotly.graph_objs as go
from plotly.offline import iplot

data = [go.Bar(x=[i for i in range(5)], y=[i for i in range(5)], orientation="h")]
layout = go.Layout(
    bargap=0.1,
    xaxis=go.layout.XAxis(type="log", title="log"),
    template="ggplot2",
    hovermode="y",
    margin=dict(l=200, t=35),
)
iplot(go.Figure(data, layout))

c = ipywidgets.Checkbox(description="%", value=False)
display(c)

Screenshot 2019-04-04 at 11 24 23

plotly 3.7.1
ipython 7.4.0

JupyterLab v0.35.4
Known labextensions:
app dir: /Users/valery/.local/share/virtualenvs/arche-lm24e12g/share/jupyter/lab
@jupyter-widgets/jupyterlab-manager v0.38.1 enabled OK
@jupyterlab/plotly-extension v0.18.2 enabled OK
plotlywidget v0.8.0 enabled OK

iplot_display_dupes.ipynb.zip

@manycoding
Copy link
Author

manycoding commented Apr 12, 2019

My current workaround - display(HTML(plot(f, include_plotlyjs=False, output_type="div"))).
It keeps the notebook size small, keeps graphs and works fast.
However, the graphs printed in this way are static so it's impossible to update them after they printed.

@jonmmease
Copy link
Contributor

Hi @manycoding,

The reason you're getting multiple displays in the notebook is because iplot and display both show the figure as a side-effect. So this is the expected behavior.

I haven't been following along closely, but it looks like the jupyter-widgets project may have just merged in support for saving/loading the widget state in the JupyterLab Notebook. See jupyter-widgets/ipywidgets#2265. It sounds like this might be the best solution for your usecase.

@manycoding
Copy link
Author

@jonmmease So there is no other way to have both ipywidgets and graphs (printed with plotly) in the same cell without duplicating the first ones?
Except for cleaning the widgets.

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

No branches or pull requests

2 participants