bokeh: push_notebook does not work in Google Colaboratory
Hello!
I tried to create an interactive plot with bokeh in Google Colab. The following code renders a scatter plot as expected:
from bokeh.models import ColumnDataSource
from bokeh.plotting import figure
from bokeh.io import output_notebook, push_notebook, show
import numpy as np
output_notebook(hide_banner=True)
source = ColumnDataSource(data=dict(x=np.random.rand(10), y=np.random.rand(10)))
p = figure(output_backend="webgl")
scatter = p.scatter(source=source, x='x', y='y')
handle = show(p, notebook_handle=True)
Changing the data and calling push_notebook should change the positions of the points in the scatter plot:
scatter.data_source.data['x'] = np.random.rand(10)
scatter.data_source.data['y'] = np.random.rand(10)
push_notebook(handle)
Instead, the notebook crashes (“Runtime disconnected”). This happens with bokeh version 1.3.4. You can find a demo of the problem here.
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 15 (9 by maintainers)
I am working on this on two fronts right now-
Once the binary comms plumbing is in Colab we should be able to either expose some globals in the environment or if the above jupyter-output-spec stabilizes and is acceptable then implement that.
I’m working up a PR to add support for those comms to bokeh (and the HoloViz stack). I’ll reopen this issue since the ball is now in our court.
I’m looking into this for Colaboratory- For background Colab renders every cell’s output in a separate iframe- this has been a longstanding requirement from Google’s security team to sandbox the rendered outputs from credentials in the rest of the page. This is unfortunately not something we will be able to change.
Colab has the infrastructure for comms support but we have not exposed much of it. I’m curious how Bokeh would expect it to be exposed. Looking at https://github.com/bokeh/bokeh/blob/fbd8a6362d9abce9b873f3f528b089a9e738568f/bokehjs/src/lib/embed/notebook/index.ts#L35 Bokeh has support for Jupyter Notebooks and Jupyter Lab. Just to experiment I tried exposing Colab’s comms via the Jupyter Notebook path- this causes a lot more problems because once we define
window.Jupyterthen other code starts assuming it’s in a complete Notebook environment and lots of things break. For example this line causes the Bokeh initialization to completely break: https://github.com/bokeh/bokeh/blob/fbd8a6362d9abce9b873f3f528b089a9e738568f/bokeh/core/_templates/autoload_nb_js.js#L120.@mattpap You mention that you are working on Jupyter Widgets support- unfortunately Colab currently only supports the core widgets. We would like a more extensible system and started a discussion a while back, but have not been able to make much progress. Some of the issues are covered in https://github.com/nteract/nes/tree/master/portable-widgets.
For the crash- is Bokeh using binary comms by chance? That could be hitting https://github.com/googlecolab/colabtools/issues/587. We have not prioritized that issue as not too many users have hit it and there’s a workaround for the only case we were seeing.
I am interested in improving Bokeh support in Colab- I addded some Bokeh initialization a while back (https://github.com/googlecolab/colabtools/blob/master/google/colab/_import_hooks/_bokeh.py).
I see a few approaches, and would appreciate feedback on which is preferred:
google.colab.kernel.comm_managerand have Bokeh add explicit support for that.