I’ve run into a problem rendering images interactively using Bokeh in Jupyterlab with interactions via IPython widgets. I can get everything working, per se, but the updates are inconsistent. The plots will very frequently update to simply show a blank/transparent image, rather than the intended raster plot data.
This occurs despite confirming the data in the ColumnDataSource exists and has the expected values. I’ve tried creating deep copies of the data before passing it, and this doesn’t prevent the issue. This behavior is consistent regardless of output backend.
As far as I can tell, this doesn’t occur with line or scatter plots, separately or as part of the same interactive set of plots.
Below is a minimally reproducible example using random noise data:
import numpy as np
from bokeh.layouts import grid
from bokeh.models import ColumnDataSource, Slider
from bokeh.plotting import figure, output_notebook, show
from bokeh.io import push_notebook
import ipywidgets as widgets
output_notebook()
test_ts = np.random.uniform(size = (50,50,3,100))
init_z = int(test_ts.shape[2]/2)
scale_img = 6
img = figure(width=scale_img*test_ts.shape[0], height=scale_img*test_ts.shape[1], x_range=(0, test_ts.shape[0]), y_range=(0, test_ts.shape[1]), output_backend="webgl")
slice_dat = ColumnDataSource(data={'x': [0], 'y': [0], 'dw': [test_ts.shape[0]], 'dh': [test_ts.shape[1]], 'im': [test_ts[:,:,init_z,0]]})
img.image(image='im', x='x', y='x', dw='dw', dh='dh', source=slice_dat)
handle = show(img, notebook_handle=True)
def update_plot(time):
slice_dat.data['im'] = [test_ts[:,:,init_z,time]]
push_notebook(handle=handle)
widgets.interact(update_plot, time=widgets.IntSlider(min=0, max=test_ts.shape[3]-1, step=1, value=0))
For reference, here is an example of the behavior I’m observing.
Package versions:
Bokeh 3.4.1
Jupyter Bokeh 4.0.4
JupyterLab 4.1.8
JupyterLab Widgets 3.0.10
IPython 8.22.2
IPython Widgets 8.1.2
Any thoughts on what could be causing this or how I could further troubleshoot?
EDIT: Forgot to include Jupyter Bokeh in installed packages list.