Below is code for a standalone simplified version of what I’m trying to do. The issue is when I try to update the data and the new data is shorter in length that the previous, I get a “Size mismatch” error. If I don’t set “color_val” or set “view” in the scatter calls, there are no errors. I’m guessing there is some update called where one plot has the right size and the other doesn’t? Any help is appreciated.
import numpy as np
from bokeh.io import curdoc
from bokeh.layouts import column
from bokeh.models import ColumnDataSource, Button
from bokeh.models import CDSView, CustomJSFilter
from bokeh.plotting import figure
from bokeh.transform import factor_cmap
filtjscode = """
const indices = [];
for (let ii = 0; ii < source.get_length(); ii++) {
// Typically other real stuff here...
indices.push(true);
}
return indices;
"""
source = ColumnDataSource(data=dict(x=[], y=[], z=[], is_odd=[]))
filt = CustomJSFilter(code=filtjscode)
view = CDSView(source=source, filters=[filt])
def odd_status(val):
if val % 2 == 0:
return "No"
else:
return "Yes"
def update_data(event):
nvals = np.random.randint(2,11)
xx = np.array(range(nvals))
yy = xx**2
zz = xx**1.75
is_odd = [odd_status(val) for val in yy]
source.data = dict(x=xx, y=yy, z=zz, is_odd=is_odd)
update_data(None)
# Create figures
fig1 = figure(height=400, width=400, x_range=[0, 10], y_range=[0, 100])
fig2 = figure(height=400, width=400, x_range=[0, 10], y_range=[0, 100])
color_val = factor_cmap('is_odd', ['blue', 'orange'], ["Yes", "No"])
fig1.scatter(x='x', y='y', color=color_val, source=source, view=view)
fig2.scatter(x='x', y='z', color=color_val, source=source, view=view)
# Create widgets
button = Button(label='New Data')
button.on_click(update_data)
curdoc().add_root(column(button, fig1, fig2))