bokeh 2.0 Dropdown missing value attribute

前端 未结 1 1807
灰色年华
灰色年华 2021-01-28 19:48

bokeh 1.4.0

>>> import bokeh
>>> bokeh.__version__
\'1.4.0\'
>>> from bokeh.models import Dropdown
>>> Dropd         


        
1条回答
  •  醉梦人生
    2021-01-28 20:09

    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.

    0 讨论(0)
提交回复
热议问题