Bokeh: How to build handler for active button in CheckboxButtonGroup?

Viewed 68

I try to make handler based on active button in Bokeh CheckboxButtonGroup. This is my Button Group.

LABELS = ["Name", "Date", "Volume", "Percentage Change"]

checkbox_button_group = CheckboxButtonGroup(labels=LABELS, active=[0, 1])
checkbox_button_group.js_on_click(CustomJS(code="""
    console.log('checkbox_button_group: active=' + this.active, this.toString())
"""))

I want to make my handler function return selected button, can anyone help me to solve this?

1 Answers

If you want to get labels of the selected buttons:

checkbox_button_group.js_on_click(CustomJS(code="""
    var labels = Array.from(this.active, a => isNaN(this.labels[a]) ? this.labels[a] : Number(this.labels[a]))
    console.log(labels)
"""))
Related