Check / uncheck all checkboxes in a CheckBoxGroup

Hello,

I have a figure that has several plots stored in the list “plots”. I also have a CheckBoxGroup that has one checkbox for each plot in “plots” to toggle line visibility on/off. When the box is unchecked, the line is visible.

I would like to add a button or checkbox that checks all the boxes in “checkbox”. In JQuery if you have a checkbox #x you can check it by doing
$( ‘#x’ ).prop(“checked”, true);

``

or false to uncheck. In bokeh we can access the STATUS of checkboxes in a CheckBoxGroup by looking at the “active” attribute. But how to actually check / uncheck the boxes?

N_plots = range(len(plots))

checkbox = CheckboxGroup(labels=[str(i) for i in N_plots],active=N_plots)

iterable = [(‘p’+str(i),plots[i]) for i in N_plots]+[(‘checkbox’,checkbox)]
code = ‘’.join([‘p’+str(i)+’.visible = ‘+str(i)+’ not in checkbox.active;’ for i in N_plots])

checkbox.callback = CustomJS(args={key: value for key,value in iterable},lang=“coffeescript”, code=code)

``

I want to add:

button = Button(labels=‘Check all checkboxes’,button_type = success)

button.callback = CustomJS(args={key: value for key,value in iterable}, code=""“code to check all the checkboxes in checkbox”"")

``

Thank you

Please see this answer on Stack Overflow:

  http://stackoverflow.com/questions/39561553/bokeh-widget-callback-to-select-all-checkboxes/39562653#39562653

That answer is for a Bokeh server app, but the answer is essentially the same: you need to *set* the .active property to the list of checkboxes that you'd like to be checked, and you can set it at any time to whatever you like.

Thanks,

Bryan

···

On Sep 19, 2016, at 11:05 AM, [email protected] wrote:

Hello,

I have a figure that has several plots stored in the list "plots". I also have a CheckBoxGroup that has one checkbox for each plot in "plots" to toggle line visibility on/off. When the box is unchecked, the line is visible.

I would like to add a button or checkbox that checks all the boxes in "checkbox". In JQuery if you have a checkbox #x you can check it by doing
$( '#x' ).prop("checked", true);

or false to uncheck. In bokeh we can access the STATUS of checkboxes in a CheckBoxGroup by looking at the "active" attribute. But how to actually check / uncheck the boxes?

N_plots = range(len(plots))

checkbox = CheckboxGroup(labels=[str(i) for i in N_plots],active=N_plots)

iterable = [('p'+str(i),plots[i]) for i in N_plots]+[('checkbox',checkbox)]
code = ''.join(['p'+str(i)+'.visible = '+str(i)+' not in checkbox.active;' for i in N_plots])

checkbox.callback = CustomJS(args={key: value for key,value in iterable},lang="coffeescript", code=code)

I want to add:

button = Button(labels='Check all checkboxes',button_type = success)

button.callback = CustomJS(args={key: value for key,value in iterable}, code="""code to check all the checkboxes in checkbox""")

Thank you

--
You received this message because you are subscribed to the Google Groups "Bokeh Discussion - Public" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/5976988d-7ba4-452b-908c-c82eb92f1751%40continuum.io.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.

Thank you for the answer, I managed to replicate your example in a button CustomJS callback.

Here is the code in case someone would like to try too (“plots” is a list of plots inside a Figure “fig”), with one “clear all” button and one “check all” button:

N_plots = range(len(plots))

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

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

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

clear_button = Button(label=‘Clear all’,width=200)
clear_button_code = “”“checkbox.set(“active”,);”""+checkbox_code
clear_button.callback = CustomJS(args={key: value for key,value in iterable}, lang=“coffeescript”, code=clear_button_code)

check_button = Button(label=‘Check all’,width=200)
check_button_code = “”“checkbox.set(“active”,”""+str(N_plots)+""");"""+checkbox_code
check_button.callback = CustomJS(args={key: value for key,value in iterable}, lang=“coffeescript”, code=check_button_code)

group = widgetbox(checkbox,clear_button,check_button)

grid = gridplot([[fig,group]])

``

···

Le lundi 19 septembre 2016 12:16:26 UTC-4, Bryan Van de ven a écrit :

Please see this answer on Stack Overflow:

    [http://stackoverflow.com/questions/39561553/bokeh-widget-callback-to-select-all-checkboxes/39562653#39562653](http://stackoverflow.com/questions/39561553/bokeh-widget-callback-to-select-all-checkboxes/39562653#39562653)

That answer is for a Bokeh server app, but the answer is essentially the same: you need to set the .active property to the list of checkboxes that you’d like to be checked, and you can set it at any time to whatever you like.

Thanks,

Bryan

On Sep 19, 2016, at 11:05 AM, [email protected] wrote:

Hello,

I have a figure that has several plots stored in the list “plots”. I also have a CheckBoxGroup that has one checkbox for each plot in “plots” to toggle line visibility on/off. When the box is unchecked, the line is visible.

I would like to add a button or checkbox that checks all the boxes in “checkbox”. In JQuery if you have a checkbox #x you can check it by doing

$( ‘#x’ ).prop(“checked”, true);

or false to uncheck. In bokeh we can access the STATUS of checkboxes in a CheckBoxGroup by looking at the “active” attribute. But how to actually check / uncheck the boxes?

N_plots = range(len(plots))

checkbox = CheckboxGroup(labels=[str(i) for i in N_plots],active=N_plots)

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

code = ‘’.join([‘p’+str(i)+’.visible = ‘+str(i)+’ not in checkbox.active;’ for i in N_plots])

checkbox.callback = CustomJS(args={key: value for key,value in iterable},lang=“coffeescript”, code=code)

I want to add:

button = Button(labels=‘Check all checkboxes’,button_type = success)

button.callback = CustomJS(args={key: value for key,value in iterable}, code=""“code to check all the checkboxes in checkbox”"")

Thank you


You received this message because you are subscribed to the Google Groups “Bokeh Discussion - Public” group.

To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].

To post to this group, send email to [email protected].

To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/5976988d-7ba4-452b-908c-c82eb92f1751%40continuum.io.

For more options, visit https://groups.google.com/a/continuum.io/d/optout.