Hi,
Added the code below with test source.
Is it possible to update the second multiselect widget to only show values that have data points for what the user selects on the first multiselect widget.
So in the below code if the user selects ‘a’ the second multiselect tool updates and only showes ‘a-2’, ‘a-5’.
from bokeh.io import show
from bokeh.layouts import column
from bokeh.models import ColumnDataSource, CDSView, BooleanFilter, CustomJSTransform, MultiSelect, CustomJS
from bokeh.plotting import figure
from bokeh.transform import transform
import numpy as np
p = figure()
ds = ColumnDataSource(dict(x=list(range(10)),
y=list(range(10)),
names = ['a', 'b', 'c', 'c', 'd', 'd', 'a', 'a', 'c', 'c'],
name_id = ['a-5', 'b-1', 'c-1', 'c-1', 'd-1', 'd-1', 'a-2', 'a-5', 'c-2', 'c-2']))
b = BooleanFilter([True if x == 'a' else False for x in ds.data['names']])
selectoroptions = [str(x) for x in sorted(np.unique(ds.data['names']))]
ms = MultiSelect(title= 'MC Experiment:', value = ['a'],
options=selectoroptions)
b_id = BooleanFilter([True if x == 'a-5' else False for x in ds.data['name_id']])
selectoroptions = [str(x) for x in sorted(np.unique(ds.data['name_id']))]
ms_id = MultiSelect(title= 'ID:', value = ['a-5'],
options=selectoroptions)
ms.js_on_change('value', CustomJS(args = dict(f=b, source=ds, columnName = 'names'),
code="""\
const val = cb_obj.value;
f.booleans = Array.from(source.data[columnName]).map(d => val.includes(d != null && d.toString()));
source.change.emit();
"""))
ms_id.js_on_change('value', CustomJS(args = dict(f=b_id, source=ds, columnName = 'name_id'),
code="""\
const val = cb_obj.value;
f.booleans = Array.from(source.data[columnName]).map(d => val.includes(d != null && d.toString()));
source.change.emit();
"""))
view = CDSView(source=ds, filters=[b, b_id])
tr = CustomJSTransform(v_func="return xs.map(x => 10 * x);")
p.scatter('x', transform('y', tr), view=view, source=ds, color='red')
show(column(p, ms, ms_id))