有没有在Bokeh
-framework中创建条件CheckboxGroup
的简单方法?有条件的是,当触发另一个Bokeh
-widget时,将根据触发小部件中的值填充CheckboxGroup
。
因此,例如,如果我有一个带有选项[a, b]
的Select
-widget形式的下拉菜单,以及一个指向这些“新”选项{'a' : ['aa','bb','cc'], 'b' : ['dd','ee','ff']}
的单独Python-dict -我如何根据特定的选择创建一个复选框?
伪代码:
options_dict = {'a' : ['aa','bb','cc'], 'b' : ['dd','ee','ff']}
dropdown = Select(title="a dropdown menu:", options = ['a', 'b'], value='a')
# let all sub-options be the default option
checkbox = CheckboxGroup(labels=['aa','bb','cc','dd','ee','ff'], active=['aa','bb','cc','dd','ee','ff'])
# assume we have some function that is updating and fetching the value of the 'dropdown'
def select_something():
selected_attribute = dropdown.value()
return selected_attribute
def update():
selected_attribute = select_something()
# update the CheckBox contents - obviously Pseudo-code
checkbox.labels = options_dict[selected_attribute]
# and have all of them "pre-checked"
checkbox.active = options_dict[selected_attribute]
dropdown.on_change('value', lambda attr, old, new: update())
谢谢
发布于 2017-11-16 22:18:40
您可以通过更改复选框组的active
参数来更新该复选框组。
这是一个按顺序引用每个复选框的整数列表,如果您有3个复选框,并且只希望选中最后一个复选框,则可以将active
列表更改为[2]
;如果只希望选中第一个和最后一个复选框,则可以将其更改为[0,2]
https://stackoverflow.com/questions/47267853
复制相似问题