首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Bokeh Python条件CheckboxGroup

Bokeh Python条件CheckboxGroup
EN

Stack Overflow用户
提问于 2017-11-13 23:28:24
回答 1查看 756关注 0票数 0

有没有在Bokeh-framework中创建条件CheckboxGroup的简单方法?有条件的是,当触发另一个Bokeh-widget时,将根据触发小部件中的值填充CheckboxGroup

因此,例如,如果我有一个带有选项[a, b]Select-widget形式的下拉菜单,以及一个指向这些“新”选项{'a' : ['aa','bb','cc'], 'b' : ['dd','ee','ff']}的单独Python-dict -我如何根据特定的选择创建一个复选框?

伪代码:

代码语言:javascript
运行
复制
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())

谢谢

EN

回答 1

Stack Overflow用户

发布于 2017-11-16 22:18:40

您可以通过更改复选框组的active参数来更新该复选框组。

这是一个按顺序引用每个复选框的整数列表,如果您有3个复选框,并且只希望选中最后一个复选框,则可以将active列表更改为[2];如果只希望选中第一个和最后一个复选框,则可以将其更改为[0,2]

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47267853

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档