Skip to content Skip to sidebar Skip to footer

Bokeh - Check Checkboxes With A Button/checkbox Callback

How can I check checkboxes in a CheckBoxGroup by clicking a button or checking a separate checkbox in bokeh? I am aware of this solution in javascript jquery check uncheck all chec

Solution 1:

I adapted the answer of Bigreddot to this question: Bokeh widget callback to select all checkboxes To have a similar effect from a CustomJS callback.

Assuming a list of plots in a figure "plots", here is an example with checkboxes that trigger line visibility:

N_plots = range(len(plots))
checkbox = CheckboxGroup(labels=[str(i) for i in N_plots],active=N_plots,width=200)

iterable = [('p'+str(i),plots[i]) for i in N_plots]+[('checkbox',checkbox)]

checkbox_code = ''.join(['p'+str(i)+'.visible = checkbox.active.includes('+str(i)+');' for i in N_plots])
checkbox.callback = CustomJS(args={key: value for key,value in iterable}, code=checkbox_code)

Here is a button that can clear all checkboxes:

clear_button = Button(label='Clear all')
clear_button_code = "checkbox.active=[];"+checkbox_code
clear_button.callback = CustomJS(args={key: value for key,value in iterable}, code=clear_button_code)

And here is a button that checks all the checkboxes:

check_button = Button(label='Check all')
check_button_code = "checkbox.active="+str(N_plots)+";"+checkbox_code
check_button.callback = CustomJS(args={key: value for key,value in iterable}, code=check_button_code)

Post a Comment for "Bokeh - Check Checkboxes With A Button/checkbox Callback"