Bokeh on GCP with Jupyter

Hello!
I’ve started to use Bokeh several weeks ago, and now I would like to implement an application within a Jupyter Notebook, on the Google Cloud environment.

My current problem is that the callback of my application is not working. I know that there is a special trick to make it work on Jupyter, but it sounds like the GCP makes it different.

If one of you has any piece of advice, it would be great!
Here is the code I used. I added output_notebook() at the beginning and I got BokehJS 2.0.0 successfully loaded.

Here is the display I got. The button start (hidden below) is not working.

Thanks,
Luc

@Luc That code is for a Bokeh server application. When you pass a simple layout object to show you are limited to “standalone” output, which is only purely JS and HTML and cannot have e.g. real python callbacks.

It is possible to embed Bokeh server applications inside notebooks, but they have their own specific format that you will need to follow. You can see an example here:

bokeh/notebook_embed.ipynb at branch-3.0 · bokeh/bokeh · GitHub

More or less, the entire app needs to be defined by a function, and that function is passed to show.

However, I should also note that Bokeh server applications require the ability to open a websocket connection. If GCP blocks this (I don’t know that it does either way) then Bokeh server applications will not be an option there. A quick test would be to try the linked notebook above first.

Another possibility to mention: If you just need one-way comms, i.e. you want to push new updates from python in the notebook to the plot, then you could consider notebook comms instead. These do not rely on a Bokeh server running (but also can’t trigger callbacks from the plot, i.e. on selections on widget events).

1 Like

Many thanks @Bryan for your reply.
I’ve just tried to run your linked notebook, and it seems that it is indeed not possible on GCP because there is no opening window or display right after.
Anyway I’m gonna use the other Bokeh techniques! :smiley:

@Luc assuming it worked, the output would be in an output cell inline in the notebook. Just for helpful reference for us, can you run the linked notebook again and open up the browser’s JavaScript console and report any errors shown there?

Sure, here is the output I get and this is empty (same result if I add notebook_url).
But I just don’t know how to get access to a browser’s console within GCP, I’m not so familiar with this. Would you know?

image

@luc the browser console is intrinsic to your browser, and is independent of GCP. You can open it any time on any site. However, accessing it varies by browser type, so you will need do to a web search for something like

< your browser type > js console

to find the instructions for your specific browser.

Ok thanks, here then is the display I have.

image

That’s consistent with websocket connections being blocked, thanks for confirming. FYI push_notebook uses the Jupyter supported websocket comms API, which services like GCP, Colab, etc. have whitelisted. So I would expect it should function. People have also done somewhat things like call kernel.execute in JS callbacks to “return” values from BokehJS to Python. I regard this as somewhat hacky, but depending on your specific circumstances it might serve fine.