Update figure in Jupyter Lab

Hi, I am having trouble migrating my code from Jupyter Notebooks to Jupyter Lab. I am trying to dynamically update the glyph features based on my python code. In notebooks I have been using handles and push_notebook function.

I can’t find the way to achieve the similar behavior in Jupyter Lab.

For example, I would like to change the color to red for the glyphs in the simple example below.

Any help would be appreciated. J

from bokeh.plotting import figure, show, output_notebook
from bokeh.models import ColumnDataSource
from bokeh.io import push_notebook
output_notebook()


p = figure(width=400, height=400)
r = p.circle([1,2,3], [1,2,3])
handle = show(p, notebook_handle=True)

image

r.glyph.fill_color="red"
push_notebook(handle=handle)

Have you installed the jupyter_bokeh extension for JupyterLab?

Using with Jupyter — Bokeh 2.4.3 Documentation

Hi, sure, I have.

This is my pip freeze for jupyter:

pip freeze | grep jupyter
jupyter-bokeh==3.0.4
jupyter-core==4.11.1
jupyter-server==1.18.1
jupyter_client==7.3.5
jupyterlab==3.4.7
jupyterlab-pygments==0.2.2
jupyterlab-widgets==3.0.3
jupyterlab_server==2.15.1

What version of Bokeh? Will have to just try to repro when I get some time, I don’t have any other immediate suggestions (beyond checking the browser JS console for any errors or logs)

I really appreciate your effort. The versions are as follows:

bokeh==2.4.3
jupyter-bokeh==3.0.4

I haven’t checked the browser console though. Now, when I am looking at it, it says the following:

> Exception opening new comm jlab_core.1d4a092221669bba35bb.js:2:996515
>     _handleCommOpen http://localhost:8888/static/lab/jlab_core.1d4a092221669bba35bb.js?v=1d4a092221669bba35bb:2
>     _handleMessage http://localhost:8888/static/lab/jlab_core.1d4a092221669bba35bb.js?v=1d4a092221669bba35bb:2
>     _msgChain http://localhost:8888/static/lab/jlab_core.1d4a092221669bba35bb.js?v=1d4a092221669bba35bb:2
>     (Async: promise callback)
>     _onWSMessage http://localhost:8888/static/lab/jlab_core.1d4a092221669bba35bb.js?v=1d4a092221669bba35bb:2

Well, that’s definitely the proximate cause. Bokeh update messages go over a Jupyter Comms channel, so if the comm fails to open then for sure things won’t work. I don’t offhand know why comms init would fail, though. I would suggest trying out some older minor revisions of jupyter-lab to see if that makes any difference. Perhaps something changed on the Jupyter side of things recently. Maybe there is also some Jupyter setting or configuration that would afford more detailed error messages.

I went all the way down to the version 3.0.14 of Jupyterlab with no change in behavior. Also, I noticed even more descriptive error that is displayed right after I start the Jupyter in the browser:


Plugin '@bokeh/jupyter_bokeh' failed to activate. jlab_core.1d4a092221669bba35bb.js:2:1351476
    o http://localhost:8888/static/lab/jlab_core.1d4a092221669bba35bb.js?v=1d4a092221669bba35bb:2
    (Async: promise callback)
    o http://localhost:8888/static/lab/jlab_core.1d4a092221669bba35bb.js?v=1d4a092221669bba35bb:2
    start http://localhost:8888/static/lab/jlab_core.1d4a092221669bba35bb.js?v=1d4a092221669bba35bb:2
    G http://localhost:8888/static/lab/7796.1d8cb0bc59e275d6464f.js?v=1d8cb0bc59e275d6464f:1
    e http://localhost:8888/static/lab/main.9907354c68bf45c5d68c.js?v=9907354c68bf45c5d68c:1
    37559 http://localhost:8888/static/lab/main.9907354c68bf45c5d68c.js?v=9907354c68bf45c5d68c:1
    a http://localhost:8888/static/lab/main.9907354c68bf45c5d68c.js?v=9907354c68bf45c5d68c:1
    <anonymous> http://localhost:8888/static/lab/main.9907354c68bf45c5d68c.js?v=9907354c68bf45c5d68c:1
    <anonymous> http://localhost:8888/static/lab/main.9907354c68bf45c5d68c.js?v=9907354c68bf45c5d68c:1
Error: No provider for: jupyter.extensions.jupyterWidgetRegistry.
    resolveRequiredService http://localhost:8888/static/lab/jlab_core.1d4a092221669bba35bb.js?v=1d4a092221669bba35bb:2
    r http://localhost:8888/static/lab/jlab_core.1d4a092221669bba35bb.js?v=1d4a092221669bba35bb:2
    activatePlugin http://localhost:8888/static/lab/jlab_core.1d4a092221669bba35bb.js?v=1d4a092221669bba35bb:2
    o http://localhost:8888/static/lab/jlab_core.1d4a092221669bba35bb.js?v=1d4a092221669bba35bb:2
    start http://localhost:8888/static/lab/jlab_core.1d4a092221669bba35bb.js?v=1d4a092221669bba35bb:2
    G http://localhost:8888/static/lab/7796.1d8cb0bc59e275d6464f.js?v=1d8cb0bc59e275d6464f:1
    e http://localhost:8888/static/lab/main.9907354c68bf45c5d68c.js?v=9907354c68bf45c5d68c:1
    37559 http://localhost:8888/static/lab/main.9907354c68bf45c5d68c.js?v=9907354c68bf45c5d68c:1
    a http://localhost:8888/static/lab/main.9907354c68bf45c5d68c.js?v=9907354c68bf45c5d68c:1
    <anonymous> http://localhost:8888/static/lab/main.9907354c68bf45c5d68c.js?v=9907354c68bf45c5d68c:1
    <anonymous> http://localhost:8888/static/lab/main.9907354c68bf45c5d68c.js?v=9907354c68bf45c5d68c:1
jlab_core.1d4a092221669bba35bb.js:2:1351528

It happens on firefox 104 (snap and appimage) and chromium as well on both Ubuntu 22.04 and Windows 10. So it seems I am missing something global here.

@JRO at this point it probably best to file an actual issue with these details:

Will do, thank you very much.

Just to close this up. New version of jupyter_bokeh (3.0.5) has this issue fixed. Thank you @Bryan for your time and advice.

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.