Cannot embed bokeh server in notebook through JupyterHub

Hello,

After many tries I have been unable to display a bokeh app within a notebook on JupyterHub. I can embed a bokeh server in a Jupyter notebook on my local machine, and standalone bokeh content shows up on the remote machine running JupyterHub. But it’s when using bokeh servers and JupyterHub that things go awry.

I have followed all the steps described here, with nbserverproxy installed and the corresponding extension enabled. I’m using the notebook_embed proposed as an example. I modified the remote_jupyter_proxy_url function given by @cbanek in the docs so that base_url corresponds to the remote server domain name.

When I call show(bkapp, notebook_url=remote_jupyter_server_url), I notice that the remote_jupyter_proxy_url function is actually called twice. The first time port is None and the second time it is randomly assigned somewhere in the 30000-40000. The full_url finally returned is something like https://my.remote.server/user/my-username/port and when I try to access that URL in a separate tab, the window is empty (console says the resources fail to load) but the tab title is ‘Bokeh Application’, so I figured there is at least something actually working here. As for the browser in the notebook tab, itsays it "failed to load Bokeh session’ and ‘Could not open websocket’.

I have tried to do the same in another context, with a Littlest JupyterHub instance specially set up for that purpose on my local network at home, to no avail.

Since I have similar issues in these two different JupyterHub implementations, I think I must be doing something wrong in both cases or there is something broken somewhere.

I know this issue does not deal with bokeh per se but I guess this is the right community to ask for help! Many thanks in advance.

I will provide the code I have in my notebook in a separate post as I’m limited to two links per post as a new poster.

@Theom unfortunately I have never used jupyter-hub so I don’t actually have any experience to relate. But here are two suggestions to look for more information:

Check the new issue

Earlier this week there was an issue suggesting that the extension external package name has been changed to jupyter-server-proxy: https://github.com/bokeh/bokeh/issues/10897 Perhaps that is relevant, it would be good for a jupyter-hub user to verify things, actually.

Check the original PR

The PR that added support for this is here: https://github.com/bokeh/bokeh/pull/7686 thre might be useful extra information or discussion there, or you might be able to ping some of the participants there (who are jupyter-hub users) for help

Also, FYI, the code above was plaintext quoted, rather than code-formatted. To apply code formatting, either use the </> icon on the editing toolbar, or put triple backtick ``` fences around the code blocks.

Many thanks for your response.

Indeed I had realized that nbserverproxy was now jupyter-server-proxy and tried with the latter package (with only one of them installed at any given time to avoid conflicts). Unfortunately it did not work, and in fact it was worse with jupyter-server-proxy as the URL did not point to a ‘Bokeh Application’ tab. But in the issue you mention there is a link to additional installation guidance compared to the jupyter-server-proxy project readme. I will try this and let you know.

Thanks for the tip on code formatting, I will do so next time. I deleted that post.

Forgot to give you an update.

In fact using jupyter-server-proxy worked. I just had to enable the serverextension and restart my server (Control Panel on the web UI). Also, for JupyterLab support the corresponding server-proxy labextension should be installed.

I would recommend an update of the Bokeh docs so that it refers to jupyter-server-proxy instead of nbserverproxy. Also, users should make sure the serverextension is enabled (using jupyter serverextension --list).

@Theom would you like to rewrite the docs copy and submit a PR? I don’t feel confident to describe a process I have no firsthand experience with.

Yes I guess I could build on what’s already there and only modify the specifics on the use of jupyter-server-proxy.

1 Like

If you are hoping to deploy Bokeh dashboards to be accessed by other users of your JupyterHub (e.g. non-technical colleagues), please take a look at my ContainDS Dashboards project. It is an extension for JupyterHub allowing you to spin up a dedicated dashboard accessible as a web app within your JupyterHub.

It’s actually based on jupyter-server-proxy, but designed to connect to JupyterHub’s authentication, rather than to sit behind an individual JupyterLab session.