bokeh 2.0 Dropdown missing value attribute

余生颓废 提交于 2020-05-17 09:07:07

问题


bokeh 1.4.0

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

bokeh 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'

Is there another attribute that is meant to be used now in place of value?

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


回答1:


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.

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 will contain the menu item that you have clicked.



来源:https://stackoverflow.com/questions/60715996/bokeh-2-0-dropdown-missing-value-attribute

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!