I am trying to set up a callback in Bokeh where I have an AutocompleteInput and Slider that both trigger the same callback that updates the CDS data based on whatever the combination of inputs are.
So the process for the user would be:
1: enter a value in the AutocompleteInput widget and view the data at the default slider position
2: adjust the slider to see how the data changes for whatever was entered into the AutocompleteInput
3: enter something new into the AutocompleteInput widget and view the data at whatever the slider was left at.
I run my app using a local server:
bokeh serve --show my_app
Here is the current iteration of my widget/callback code that I have tried:
source = ColumnDataSource(data=dict(colors=color, colors_pred_data=colors_pred_labels))
autocomp = AutocompleteInput(title="", completions=product_names, case_sensitive=False)
heat_slider = Slider(start=1, end=11, value=6, step=1, title="Heat")
def marker_callback(attr, old, new):
if(autocomp.value == "Ecosystem"):
source.data['colors'] = color
source.data['colors_pred_data'] = colors_pred_labels;
else:
source.data['colors_pred_data'] = product_values[autocomp.value]
if(heat_slider.value == "1"):
source.data['colors'] = product_sources0_001[autocomp.value]
elif(heat_slider.value == "2"):
source.data['colors'] = product_sources0_01[autocomp.value]
elif(heat_slider.value == "3"):
source.data['colors'] = product_sources0_05[autocomp.value]
elif(heat_slider.value == "4"):
source.data['colors'] = product_sources0_1[autocomp.value]
elif(heat_slider.value == "5"):
source.data['colors'] = product_sources0_25[autocomp.value]
elif(heat_slider.value == "6"):
source.data['colors'] = product_sources0_5[autocomp.value]
elif(heat_slider.value == "7"):
source.data['colors'] = product_sources[autocomp.value]
elif(heat_slider.value == "8"):
source.data['colors'] = product_sources10[autocomp.value]
elif(heat_slider.value == "9"):
source.data['colors'] = product_sources50[autocomp.value]
elif(heat_slider.value == "10"):
source.data['colors'] = product_sources100[autocomp.value]
elif(heat_slider.value == "11"):
source.data['colors'] = product_sources500[autocomp.value]
heat_slider.on_change('value', marker_callback)
autocomp.on_change('value', marker_callback)
Thank you for any help!
heat_slider.value was not registering in the callback because I had the number values in quotes: (heat_slider.value == "1")
Removing the quotes from all heat_slider.value if statements got the callback to work.