bokeh / jupyter_bokeh

An extension for rendering Bokeh content in JupyterLab notebooks
BSD 3-Clause "New" or "Revised" License
254 stars 48 forks source link

Plots missing after tab refresh in jupyterlab 0.33 #49

Closed parente closed 4 years ago

parente commented 6 years ago
  1. Install bokeh 0.12.16 or 0.13.0, jupyterlab_bokeh 0.6, and jupyterlab 0.33.
  2. Run the following in a notebook cell and see the plot show up as expected.
    
    from bokeh.io import push_notebook, show, output_notebook
    from bokeh.layouts import row
    from bokeh.plotting import figure
    output_notebook()

opts = dict(plot_width=250, plot_height=250, min_border=0)

p1 = figure(**opts) r1 = p1.circle([1,2,3], [4,5,6], size=20)

p2 = figure(**opts) r2 = p2.circle([1,2,3], [4,5,6], size=20)

get a handle to update the shown cell with

t = show(row(p1, p2), notebook_handle=True)


3. Refresh the browser tab.
4. When Lab reloads, the plots are missing.
5. `Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing` shows in the JS console instead.

The plots did reappear properly after refresh in lab 0.32 with jupyterlab_bokeh 0.5.
canavandl commented 6 years ago

Thanks for the quality report @parente

~I'm able to see the same thing locally. It appears to be a race condition where the plot cell is executed (on refresh) before the output_notebook cell is finished loading BokehJS and creating the window.Bokeh object.~

Upon further investigation, it appears that the issue is the bokeh.io.output_notebook call embeds some JS in the notebook as part of a mime bundle. When the page is reloaded, this JS is evaled before the notebook is rendered, so the BokehJS loading is stopped here: https://github.com/bokeh/bokeh/blob/13baccbb2835f7d5831c22b5cf68214e89c02618/bokeh/core/_templates/autoload_js.js#L79

canavandl commented 6 years ago

@parente a work-around is to use

from bokeh.plotting import output_notebook, figure, show

output_notebook(hide_banner=True)

which will load BokehJS without checking for the notebook content being reading, so that plots will render correctly on reloading.

parente commented 6 years ago

Thanks @canavandl. That does indeed workaround the problem.

bryevdv commented 5 years ago

noting still an issue with 1.0.0next but workaround still works too

cuspime commented 4 years ago

I have a similar problem, when I refresh the page of my Jupyter notebook, no plots are shown. As suggested, I am using

output_notebook(hide_banner=True)

But this does not solve the problem. I'd like the plots to show automatically in its latest state before refreshing, like matplotlib or seaborn do...

bryevdv commented 4 years ago

@cuspime certainly we would like that to work to, though please understand the situation is very different and much more complicated than with MPL or seaboard, which only store simple PNGs. Bokeh has an entire separate JavaScript runtime that needs to execute and re-constitute live interactive plots, and that has to integrate with the notebook/jupyterlab which itself is a huge and complicated JavaScript runtime.

This used to work. I am not sure what changed (on either side) to affect things. I will relay the same advice I did in #29 which is to raise a new issue (linked to this one) in the main Bokeh repo in order to raise the visibility on this issue (this repo does not see as much attention)

mattpap commented 4 years ago

I did some debugging today and there are several issues that need resolving to make the broad problem go away. I also noticed that integration with jupyter widgets doesn't fully work after a reload (can't update state), which significantly raises the priority of this issue to me.

bryevdv commented 4 years ago

@mattpap did you mean to add this to 2.0.2? Or are we not tracking versions? (I have no idea what intentions here re: versioning this repo)

mattpap commented 4 years ago

The intention is to have 2.0.1 of jupyter_bokeh as soon as I sort out new tokens.

bryevdv commented 4 years ago

I can add a new token to the vault if that's simplest