簡體   English   中英

散景:如何從多選下拉列表中取消選擇所有值?

[英]Bokeh: How to un-select all the values from multi-select drop down list?

我在 Bokeh 應用程序中有一個 MultiSelect 下拉列表。 我想在我的工作完成后取消選擇所有值。

據我所知,小部件本身沒有提供UI交互來清除它。 您可以使用帶有CustomJS回調的按鈕來重置MultiSelect值:

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)

在單擊按鈕之前:

在此處輸入圖片說明

單擊按鈕后:

在此處輸入圖片說明

“全選”也可以做到這一點。

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)

它看起來如何

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM