bokeh 2.0下拉缺失值属性 [英] bokeh 2.0 Dropdown missing value attribute

查看:67
本文介绍了bokeh 2.0下拉缺失值属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

散景1.4.0

>>> import bokeh
>>> bokeh.__version__
'1.4.0'
>>> from bokeh.models import Dropdown
>>> Dropdown().value is None
True

散景2.0

>>> import bokeh
>>> bokeh.__version__
'2.0.0'
>>> from bokeh.models import Dropdown
>>> Dropdown().value is None
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'Dropdown' object has no attribute 'value'

是否还有另一个可以代替价值使用的属性?

请参见此处以供使用-value属性的大小写.

see here for a use-case of the value attribute.

推荐答案

Dropdown.value是Bokeh用户不打算使用的实现细节.除此之外,Dropdown在语义上只是按钮的集合.它不应该具有 any 的状态,它应该像常规按钮一样将on_click事件调度为常规按钮,就像在2.0中一样.这就是为什么value属性已在2.0.0中删除的原因.

Dropdown.value was an implementation detail that was not meant to be used by Bokeh users, according to its docstring. Apart from that, Dropdown semantically is just a collection of buttons. It should not have any sort of state, it should just dispatch the on_click event as a regular button, just as it does in 2.0. And that's why the value attribute has been removed in 2.0.0.

为了在单击下拉按钮时触发Python代码,您可以使用类似的

In order to trigger Python code on a dropdown button click, you can use something like

from bokeh.models import Dropdown

d = Dropdown(label='Click me', menu=['a', 'b', 'c'])


def handler(event):
    print(event.item)


d.on_click(handler)

event.item将包含您单击的菜单项.

event.item will contain the menu item that you have clicked.

这篇关于bokeh 2.0下拉缺失值属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆