Hi, I am new to bokeh applications with streamlit. I am trying to use customJS callback to update my plot if there is any change in the select widgets. I made up the following code and unfortunately plot is not updating after the change in select value.
here is the code snippet:
plot_data = my_total_data
coloring = Select(title="Select for coloring:", value="group_1", options=param_list_1)
color_label = coloring.value
sizing = Select(title="Select for sizing:", value="size_1", options=param_list_2)
sizing_label = sizing.value
palette = glasbey[:len(plot_data[color_label].unique())]
color_map=bokeh.models.CategoricalColorMapper(factors=plot_data[color_label].unique(),palette=palette)
plot_data['Size'] = get_sizer(plot_data[sizing_label], 10, 40)
plot_data['Half_Size'] = plot_data['Size']/1000
source = ColumnDataSource(plot_data.reset_index())
p = figure( plot_width=800, plot_height=600,
title = st.session_state.model_label,
tools='''pan,lasso_select,box_select,wheel_zoom,reset''',
active_scroll = 'wheel_zoom',active_inspect = None,
toolbar_location = 'above')
p.add_layout(annotations.Legend(), 'right')
p.legend.click_policy = 'hide'
p.scatter(x='1st_Component',y='2nd_Component',
color={'field': color_label, 'transform': color_map},
legend=color_cat_label, source=source)
callback = CustomJS(args=dict(source=source,plot=p,coloring=coloring,sizing=sizing), code="""
var data = source.data
var a =coloring.value;
var s = sizing.value;
var palette = glasbey[:len(data[a].unique())];
var color_map = bokeh.models.CategoricalColorMapper(factors=data[a].unique(),palette=palette)
source = ColumnDataSource(data=data)
plot.color={'field': color_cat_label, 'transform': color_map}
plot.legend=color_cat_label
plot.source = source
plot.change.emit()
""")
coloring.js_on_change('value', callback)
sizing.js_on_change('value', callback)
event_result = streamlit_bokeh_events(
events="SelectEvent",
bokeh_plot=column(row(coloring,sizing,width=800),p),
key="foo2",
refresh_on_update=True,
debounce_time=0,
)
Above code is able to plot with colormap based on groups but not able change if I change coloring select widget value. can someone help me out !!!