Bokeh does not render any more in Jupyter lab

I am going back to a project which I use bokeh to show plots in jupyter lab. This worked when I last was working on the project, and now it does not work any more.

This is the code which does NOT render in a jupyter lab notebook:

import bokeh
print("bokeh", bokeh.__version__)
import bokeh.io
import bokeh.plotting
import numpy as np
import notebook, IPython, jupyter, jupyter_bokeh
print("notebook", notebook.__version__, "IPython", IPython.__version__, "jupyter_bokeh", jupyter_bokeh.__version__)
bokeh.io.output_notebook()

x=np.arange(100)
y1=np.random.randn(100)
y2=np.random.randn(100)
source = bokeh.models.ColumnDataSource(data=dict(x=x,y1=y1,y2=y2))
xdr = bokeh.models.Range1d(start=0, end=99)
p1 = bokeh.plotting.figure(height=100, width=600,tools="xpan,box_zoom,wheel_zoom,xbox_select,reset,undo", toolbar_location="above",x_axis_location="above", x_range=xdr)
p1.line('x', "y1", source=source)
p2 = bokeh.plotting.figure(height=100, width=600,tools="", toolbar_location=None,x_axis_location="below", x_range=xdr)
p2.line('x', "y2", source=source)
fig=bokeh.layouts.gridplot([p1,p2], ncols=1)
bokeh.plotting.show(fig)

The output is:

bokeh 3.7.3
notebook 7.4.2 IPython 9.2.0 jupyter_bokeh 4.0.5

BokehJS 3.1.1 successfully loaded.

The following is shown on the Forefox JS console:

Starting WebSocket: ws://localhost:8888/api/kernels/aa4fb177-26f0-46b8-8cc7-710a3424ea63 default.js:69:20
Keeping old LSP connection as the new kernel uses the same language notebooklspadapter.js:160:24
Bokeh: BokehJS not loaded, scheduling load and callback at 
Date Fri Jun 06 2025 16:15:33 GMT+0200 (Central European Summer Time)
jlab_core.2668b0565326e70d2bbc.js:227:13
Bokeh: injecting script tag for BokehJS library:  https://cdn.bokeh.org/bokeh/release/bokeh-3.7.3.min.js jlab_core.2668b0565326e70d2bbc.js:261:15
Bokeh: injecting script tag for BokehJS library:  https://cdn.bokeh.org/bokeh/release/bokeh-gl-3.7.3.min.js jlab_core.2668b0565326e70d2bbc.js:261:15
Bokeh: injecting script tag for BokehJS library:  https://cdn.bokeh.org/bokeh/release/bokeh-widgets-3.7.3.min.js jlab_core.2668b0565326e70d2bbc.js:261:15
Bokeh: injecting script tag for BokehJS library:  https://cdn.bokeh.org/bokeh/release/bokeh-tables-3.7.3.min.js jlab_core.2668b0565326e70d2bbc.js:261:15
Bokeh: injecting script tag for BokehJS library:  https://cdn.bokeh.org/bokeh/release/bokeh-mathjax-3.7.3.min.js jlab_core.2668b0565326e70d2bbc.js:261:15
Bokeh: all BokehJS libraries/stylesheets loaded jlab_core.2668b0565326e70d2bbc.js:233:17
Bokeh: BokehJS plotting callback run at 
Date Fri Jun 06 2025 16:15:33 GMT+0200 (Central European Summer Time)
jlab_core.2668b0565326e70d2bbc.js:308:15
[bokeh] setting log level to: 'info' bokeh-3.1.1.min.js:183:1311
Bokeh: all callbacks have finished jlab_core.2668b0565326e70d2bbc.js:211:13
[bokeh] JS/Python version mismatch bokeh-3.1.1.min.js:165:5733
[bokeh] Library versions: JS (3.1.1) / Python (3.7.3) bokeh-3.1.1.min.js:165:5777
Uncaught Error: could not resolve type 'BoxInteractionHandles', which could be due to a widget or a custom model not being registered before first usage
    y bokeh-3.1.1.min.js:211
    error bokeh-3.1.1.min.js:211
    _resolve_type bokeh-3.1.1.min.js:211
    _decode_object_ref bokeh-3.1.1.min.js:211
    _decode bokeh-3.1.1.min.js:211
    _decode_plain_object bokeh-3.1.1.min.js:211
    _decode bokeh-3.1.1.min.js:211
    _decode_object_ref bokeh-3.1.1.min.js:211
    _decode bokeh-3.1.1.min.js:211
    _decode_plain_object bokeh-3.1.1.min.js:211
    _decode bokeh-3.1.1.min.js:211
    _decode_object_ref bokeh-3.1.1.min.js:211
    _decode bokeh-3.1.1.min.js:211
    _decode_plain_array bokeh-3.1.1.min.js:211
    f bokeh-3.1.1.min.js:178
    _decode_plain_array bokeh-3.1.1.min.js:211
    _decode bokeh-3.1.1.min.js:211
    _decode_plain_object bokeh-3.1.1.min.js:211
    _decode bokeh-3.1.1.min.js:211
    _decode_object_ref bokeh-3.1.1.min.js:211
    _decode bokeh-3.1.1.min.js:211
    _decode_plain_array bokeh-3.1.1.min.js:211
    f bokeh-3.1.1.min.js:178
    _decode_plain_array bokeh-3.1.1.min.js:211
    _decode bokeh-3.1.1.min.js:211
    _decode_plain_object bokeh-3.1.1.min.js:211
    _decode bokeh-3.1.1.min.js:211
    _decode_object_ref bokeh-3.1.1.min.js:211
    _decode bokeh-3.1.1.min.js:211
    _decode_plain_object bokeh-3.1.1.min.js:211
    _decode bokeh-3.1.1.min.js:211
    _decode_object_ref bokeh-3.1.1.min.js:211
    _decode bokeh-3.1.1.min.js:211
    _decode_plain_array bokeh-3.1.1.min.js:211
    f bokeh-3.1.1.min.js:178
    _decode_plain_array bokeh-3.1.1.min.js:211
    _decode bokeh-3.1.1.min.js:211
    s bokeh-3.1.1.min.js:211
    decode bokeh-3.1.1.min.js:211
    from_json bokeh-3.1.1.min.js:165
    embed_items_notebook bokeh-3.1.1.min.js:231
    embed_document debug-bokeh2.ipynb line 1 > injectedScript:5
    <anonymous> debug-bokeh2.ipynb line 1 > injectedScript:8
    <anonymous> debug-bokeh2.ipynb line 1 > injectedScript:24
    renderModel 824.85f07f87f0792b25f70b.js:1
    createRenderedMimetype widget.js:629
    createOutputItem widget.js:609
    _insertOutput widget.js:569
    onModelChanged widget.js:305
    m index.es6.js:555
    l index.es6.js:513
    emit index.es6.js:112
    _onListChanged model.js:277
    m index.es6.js:555
    l index.es6.js:513
    emit index.es6.js:112
    push observablelist.js:139
    _add model.js:226
    add model.js:146
    _onIOPub widget.js:98
    _handleIOPub future.js:236
    handleMsg future.js:205
    _handleMessage default.js:1376
    _msgChain default.js:179
    promise callback*45089/C/this._onWSMessage default.js:176
    _createSocket default.js:135
    setTimeout handler*_reconnect default.js:1457
    reconnect default.js:668
    restart default.js:638
    restartKernel sessioncontext.js:359
    restart sessioncontext.js:900
    execute index.js:1736
    execute index.es6.js:366
    g toolbar.js:1059
    s toolbar.js:682
    React 11
bokeh-3.1.1.min.js:211:113

This is really frustrating because I had exactly the same problem of the plot not rendering suddenly just a while age, see: Bokeh 3.1.1 does not render any more in jupyter notebook
How can I stop bokeh from randomly not working when Python or some other lib has to get upgraded before bitrotting commences?

OK I did upgrade python as well to 3.11.13 (from 3.7) but did not restard the jupyter command, after doing this it did work.
So upgrading both bokeh and python was the solution in this case

Well, this is immediately the issue:

bokeh 3.7.3
BokehJS 3.1.1 successfully loaded.

The version of BokehJS should always match the Python Bokeh package version. In particular, BoxInteractionHandles does not exist yet in version 3.1.1, hence the error you see. I have no idea what happened to you local system or setup that could cause this, though (I haven’t seen it occur before). Jupyter notebooks are a mess of state though, so clearing output cells and any caches is always a good thing to try.

1 Like

Unfortunately plot rendering still causes issues. For example I have a notebook where I render several plots in several cells by first calling a function which returns a Figure object and then using bokeh.plotting.show(figure) to display it.

What I see is this: whenever the show(figure) method is executed the plot is NOT shown, only the tools bar is shown. When I click the reload button on the bar, the plot is shown.

What often happens is that if I scroll off the plot inside the notebook, then back again, the plot has completely disappeared, not even the tool bar showing any more.
This might also be a Jupyter lab issue, I do not know, but it is extremely annoying. I have switched to seaborn for the plots where I can do this, but some features are only available with bokeh (or plotly but I hesitate going back that that because that has other issues).

Python package versions I am using: bokeh 3.7.3
notebook 7.4.2 IPython 9.2.0 jupyter_bokeh 4.0.5

bokehJS is 3.73 as well

When the plot is not shown and only the toolbar is, no error is shown on the JS console. Also no error is shown when the plot suddenly disappears after scrolling away and back.

The title says “Jupyter lab” but of your reported version info only lists “notebook”, can you clarify that you are running jupyter lab and not the classic notebook? If so, please report those versions, If not, do you have any of these same issues in Jupyterlab rather than the classic notebook? Do you have a reproducer notebook we can run?

Sorry, jupyterlab version is 4.4.3

I am using a notebook with this in the first cell:

import bokeh
print("bokeh", bokeh.__version__)
import bokeh.io
import bokeh.plotting
import numpy as np
import notebook, IPython, jupyter, jupyter_bokeh, jupyterlab

print("notebook", notebook.__version__, "IPython", IPython.__version__, 
      "jupyter_bokeh", jupyter_bokeh.__version__, "jupyterlab", jupyterlab.__version__)
bokeh.io.output_notebook()

x=np.arange(100)
y1=np.random.randn(100)
y2=np.random.randn(100)
def make_plot():
    source = bokeh.models.ColumnDataSource(data=dict(x=x,y1=y1,y2=y2))
    xdr = bokeh.models.Range1d(start=0, end=99)
    p1 = bokeh.plotting.figure(height=100, width=600,tools="xpan,box_zoom,wheel_zoom,xbox_select,reset,undo", toolbar_location="above",x_axis_location="above", x_range=xdr)
    p1.line('x', "y1", source=source)
    p2 = bokeh.plotting.figure(height=100, width=600,tools="", toolbar_location=None,x_axis_location="below", x_range=xdr)
    p2.line('x', "y2", source=source)
    fig=bokeh.layouts.gridplot([p1,p2], ncols=1)
    return fig
fig=make_plot()
bokeh.plotting.show(fig)

then a few dozen empty cells (to make the NB scollable)
and this in the last cell:

fig=make_plot()
bokeh.io.show(fig)

When running the cells, both of them only show the toolbar, but not the actual plot until the reload button is clicked.

However this notebook does not show the problem where the figure disappears when scrolling down and back. However I have noticed once that when scolling back from the botton plot
to the first, the area where the first plot should be was blank, but got refreshed after a second or so. Since my other plots have more datapoints it may take longer or forever for the refresh to happen.

I have recorded the behavior I see, but apparently it is not possible to upload a video here.
However i have uploaded it here because I have no idea if this is a Bokeh or Jupyter lab issue:

The problem is that this becomes much more annoying with larger notebooks: more cells disappearing more often and never coming back.

I have created a new topic for the “random disappearing and sometimes but not always reappearing” problem, as it is different from what I originally described in here, which has been solved.

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