Size mismatch when updating ColumnDataSource

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)) 

I’m thinking the bug is that I was using the same filter/view for each plot. If I make separate a filter/view the issues is resolved.

I’m not sure it’s been considered or intentended whether views can be shared between different glyphs. In this case I probably would have tried two views that share the same filter, does that work?

A single filter and two views works fine as well. I’m fine accepting that as an answer. I’ll leave it up to you as to what was is actually intended.

I’m not sure it’s been considered or intentended whether views can be shared between different glyphs.

It’s allowed since 2.4 or 3.0, because CDSView now has an associated view, which maintains its own state per context, which is per glyph renderer in this case.

I’m currently on 2.3.3 so that’s probably it.