Embedding bokeh server applications in mybinder Notebooks

I have a few bokeh server applications that run embedded inside Jupyter Notebooks (which I did by following the example given here: bokeh/notebook_embed.ipynb at 2.3.1 · bokeh/bokeh · GitHub)

Now I would like to have the applications working on Binder instances (mybinder.org), but I cannot get them to work.

When I try to load the app I get
BokehJS 1.4.0 successfully loaded
but nothing shows up.

The console gives the following errors:

GET http://localhost:39735/autoload.js?bokeh-autoload-element=1027&bokeh-absolute-url=http://localhost:39735&resources=none net::ERR_CONNECTION_REFUSED
Failed to load resource: net::ERR_CONNECTION_REFUSED   http://localhost:43097/autoload.js?bokeh-autoload-element=1017&bokeh-absolute-url=http://localhost:43097&resources=none


Couldn't process kernel message TypeError: Cannot read property 'trim' of undefined   kernel.js:1009

I do not know what I am doing wrong. Why is it not working and any advice on how to fix it?

Thank you!

Additional steps will be required on Binder due to their more complicated network configuration. AFAIK this is still the appropriate guidance:

BTW Bokeh 1.4 is quite old, I would strongly urge upgrading (and it may even be required, the kernel error message suggests that Bokeh 1.4 expects an older version of Jupyter than Binder is running).

Thank you @Bryan. I will update Bokeh version as soon as I can and the example you linked is quite helpful but I am not sure I know how to change it so the Bokeh app is embedded inside the notebook.

From what I understand, the linked example uses subprocess.Popen to execute bokeh serve and then redirects to the default 5006 port. My objective, however, is to embed the application inside the notebook.

Simply defining a bkdev(doc) function and calling it (with or without the notebook_url argument) does, unfortunately, not work.

In the example I linked above, it says:

Now we can display our application using show, which will automatically create an Application that wraps bkapp using FunctionHandler. The end result is that the Bokeh server will call bkapp to build new documents for every new sessions that is opened.

How is this Bokeh server run and call bkapp?

In the example I linked above, it says

To be clear that statement is about a Jupyter notebook that you are running and configuring and have complete control over yourself. Specifically, it assumes that there is nothing that would block or otherwise interfere the websocket connections that a Bokeh server needs to open. More pointedly: that statement may not apply to hosted services such as Binder. That is because sevices like Binder may very well have proxies or other network configurations that do interfere with Bokeh’s websockets.

I am afraid, however, that I have any personal knowledge about Binder’s network setup, or if it is possible to run Bokeh apps from Binder, and if so, what that might look like. So I am unable to offer any further advice. You might consider making an issue on the repo I linked to ask choldgraf directly, or otherwise reaching out to Binder directly to ask them if they have any specific guidance re: embedded Bokeh apps.

cc @Timo I think we might want to expand this section in the docs to make it clearer that the examples all assume users are running their own Jupyter notebooks, and that no guarantees are made about what might or might not be possible on hosted services such as Binder (because how they set up their network configuration is 100% out of our control)

1 Like

cc @jsignell @Philipp_Rudiger in case either of you has any info about Bokeh server apps directly embedded in notebooks on Binder