Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Plotly offline will not work upon page reload or from another client; will not work with ipywidgets #463

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
aggFTW opened this issue May 17, 2016 · 9 comments

Comments

@aggFTW
Copy link

aggFTW commented May 17, 2016

Hi,

We found out that the following PR: #379
ends up breaking plotly offline on page refreshes.

Upon first execution:
plotly0

And upon refresh:
plotly1

It seems like what we really should do is have an if statement on javascript that re-registers Plotly.

At the same time, if we want to use plotly with ipywidgets in an output widget, that check on __PLOTLY_OFFLINE_INITIALIZED in that PR would make it impossible to re-register Plotly from init_notebook_mode by any other browser connected to the same kernel or the same browser on a refresh. Again, this check to not re-register should be done on the javascript side, because it is the front end that knows whether Plotly is defined or not, not the server.

Thanks!
Alejandro

cc @msftristew @ellisonbg @tc0312

@aggFTW
Copy link
Author

aggFTW commented May 17, 2016

Cell 1:

from plotly.offline import init_notebook_mode
from plotly.graph_objs import Pie, Figure, Data
from plotly.offline import iplot

import plotly as plt
plt.__version__

Cell 2:

init_notebook_mode()

Cell 3:

data = [Pie(values=[1,2,3])]
fig = Figure(data=Data(data))
iplot(fig, show_link=False)

@aggFTW aggFTW changed the title Plotly offline will not work upon page reload or other client Plotly offline will not work upon page reload or from another client; will not work with ipywidgets May 17, 2016
@aggFTW
Copy link
Author

aggFTW commented May 17, 2016

We suspect this is related: #458

@yankev
Copy link
Contributor

yankev commented May 18, 2016

@aggFTW Yea, it appears that removing the check for __PLOTLY_OFFLINE_INITIALIZED in PR #379, like you said, fixes the issue (edit: of reloading the notebook).

@aggFTW
Copy link
Author

aggFTW commented May 18, 2016

@yankev well, removing the check + adding the javascript if statement would be the right thing, it seems like. Are you working on it?

@yankev
Copy link
Contributor

yankev commented May 18, 2016

@aggFTW yep, @mdtusz and I are looking at it right now.

@aggFTW
Copy link
Author

aggFTW commented May 18, 2016

Ok, thanks! 😄

@aggFTW
Copy link
Author

aggFTW commented May 18, 2016

@tc0312 and I were looking at this and we think the python check should be removed and the javascript should look something like this (we haven't tested it):

display(HTML("<script type='text/javascript'>" +
    "if (typeof window.Plotly === 'undefined') {" +
    "define('plotly', function(require, exports, module) {" +
    "get_plotlyjs()" +
    "});" +
    "require(['plotly'], function(Plotly) {" +
    "window.Plotly = Plotly;" +
    "});" +
    "}" +
    "</script>"))

We hope it helps!

@mdtusz
Copy link
Contributor

mdtusz commented May 18, 2016

Yep! This PR will solve it - just cleaning up a few things then it will be merged in.

@msftristew
Copy link

Great stuff, thanks @mdtusz.

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

5 participants