I’m trying to get the value from a slider and filter data based on that value and show the filtered data.
The way I’m doing it below is
-same data in both origin and source datasets
-plot first with origin
-filter data in source with a new value and update origin data
-continue
However, I can’t seem to be able to get it to work.
Please help…
x = np.linspace(0,10,10)
y = np.linspace(20,30,10)
z = [0,0,1,0,1,0,1,0,1,1]
origin = ColumnDataSource(data=dict(x = x, y = y, z = z))
source = ColumnDataSource(data=dict(x = x, y = y, z = z))
p = figure(plot_width=600, plot_height=400)
p.circle(‘x’, ‘y’, source=source, size=5, color=“navy”,alpha=0.5)
def callback(source=source, source2 = origin, origin = origin, window=None):
data = source2.data
r_data = source.data
data_dct_l = zip(r_data[‘x’], r_data[‘y’], r_data[‘z’])
f = cb_obj.value
filtered = [x for x in data_dct_l if x[2] == f]
for n, colname in enumerate('x y z'.split()):
r_data[colname] = [i[n] for i in filtered]
r_data.trigger('change')
sample_slider = Slider(start=0, end=1, value= 0, step=1,
title=“n”, callback=CustomJS.from_py_func(callback))
layout = column(sample_slider, p)
show(layout)
``