jeudi 15 septembre 2016

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 checkboxes with a button

however the checkboxgroup bokeh object passed in customJS can't be manipulated with .prop ! I am not sure how to do that with the bokeh checkboxgroup object.

here is what I tried, plots is a list containing different scatter plots in a figure:

checkbox = CheckboxGroup(labels=[str(i) for i in range(len(plots))],active=range(len(plots)),width=200)
iterable = [('p'+str(i),plots[i]) for i in range(len(plots))]+[('checkbox',checkbox)]
code = ''.join(['p'+str(i)+'.visible = '+str(i)+' not in checkbox.active;' for i in range(len(plots))])
checkbox.callback = CustomJS(args={key: value for key,value in iterable},lang="coffeescript", code=code)

checkbox2 = CheckboxGroup(labels=['check all'],active=[0],width=100)

checkbox2.callback = CustomJS(args={'checkbox':checkbox}, code = """
if (0 not in cb_obj.active){
    checkbox.set("active",_.range(27));
}
checkbox.trigger("change");
    """)

My first checkboxgroup works perfectly fine to trigger on/off the visibility of plots in the figure. However the second checkbox has no effect.




Aucun commentaire:

Enregistrer un commentaire