Reputation: 57
I have a MultiSelect drop-down list in Bokeh application. I want to un-select all the values after my work is done.
Upvotes: 1
Views: 1153
Reputation: 1
And the same can also be done with "select all".
from bokeh.io import show
from bokeh.models import CustomJS, MultiChoice, Button
output_file("multichoice-all-clear.html", title="states")
OPTIONS = ["foo", "bar", "baz", "quux"]
## Define the widgets
buttonAll = Button(label="Select all", button_type="success")
buttonClear = Button(label="Clear selection", button_type="success")
multi_choice = MultiChoice(value=["foo", "baz"], options=OPTIONS)
## Define callbacks/interactivity
multi_choice.js_on_change("value", CustomJS(code="""
console.log('multi_choice: value=' + this.value, this.toString())
"""))
button_callback = CustomJS(
args=dict(s=multi_choice),
code="""
s.value= s.options;
console.log('button: click!', this.toString());
""")
buttonAll.js_on_click(button_callback)
button_callback = CustomJS(
args=dict(s=multi_choice),
code="""
s.value= [];
console.log('button: click!', this.toString());
""")
buttonClear.js_on_click(button_callback)
layout = gridplot([buttonAll, buttonClear,
multi_choice], ncols=1, toolbar_location=None)
show(layout)
Upvotes: 0
Reputation: 34568
There is no UI interaction the widget itself offers as far as I know to clear it. You could make a button with a CustomJS
callback that resets the MultiSelect
values:
select = MultiSelect(options=["First", "Second", "Third"])
button = Button(label="clear")
callback = CustomJS(args=dict(s=select), code="s.value=[]")
button.js_on_event('button_click', callback)
Before clicking the button:
After clicking the button:
Upvotes: 2