Python 3.x 从多个小部件触发相同的bokeh回调

Python 3.x 从多个小部件触发相同的bokeh回调,python-3.x,bokeh,Python 3.x,Bokeh,我一直在构建一个bokeh绘图,除了绘图本身之外,它还包括两个不同的小部件。一个是下拉菜单,另一个是“清除打印”按钮 就像现在一样,“clear plot”(清除绘图)按钮对清除绘图中所有点的函数进行回调。下拉菜单用于选择将更改打印限制的值。这后一个小部件,我也想重置绘图,就像按钮点击 由于Button小部件有on_event样式事件,而Select小部件有on_change样式事件,我很难弄清楚如何对同一个函数(清除绘图的函数)进行回调,因为这两种事件类型在回调中需要不同的参数 from bo

我一直在构建一个bokeh绘图,除了绘图本身之外,它还包括两个不同的小部件。一个是下拉菜单,另一个是“清除打印”按钮

就像现在一样,“clear plot”(清除绘图)按钮对清除绘图中所有点的函数进行回调。下拉菜单用于选择将更改打印限制的值。这后一个小部件,我也想重置绘图,就像按钮点击

由于Button小部件有
on_event
样式事件,而Select小部件有
on_change
样式事件,我很难弄清楚如何对同一个函数(清除绘图的函数)进行回调,因为这两种事件类型在回调中需要不同的参数

from bokeh.models import Button, ColumnDataSource
from bokeh.events import ButtonClick 
from bokeh.models.widgets import Select

plot_data = ColumnDataSource(dict(id=[],step=[],ratio=[]))

***some code that populates the ColumnDataSoure***

#Defining button function for resetting alarms
button = Button(label="RESET ALARMS", button_type="danger")

def reset_plot(event):
    #Resetting plot
    plot_data.data = {k: [] for k in plot_data.data}

button.on_event(ButtonClick,reset_plot)
我的
Select
小部件当前的外观如下:

menu = [(str(item),str(item)) for item in list_of_items]
dropdown = Select(title='Item', value="Item 1",options=menu)

def change_limits(attr,old,new):
   *some code that changes the plotting limits*

dropdown.on_change('value',change_limits) 
我想要的基本上是一个类似于
下拉列表的东西。在更改(“选择新项目”,重置\u绘图)
回调时

from bokeh.models import Button, ColumnDataSource
from bokeh.events import ButtonClick 
from bokeh.models.widgets import Select

plot_data = ColumnDataSource(dict(id=[],step=[],ratio=[]))

***some code that populates the ColumnDataSoure***

#Defining button function for resetting alarms
button = Button(label="RESET ALARMS", button_type="danger")

def reset_plot(event):
    #Resetting plot
    plot_data.data = {k: [] for k in plot_data.data}

button.on_event(ButtonClick,reset_plot)
是否可以从
Select
小部件回调我的
reset\u plot
函数,或者我只需在
change\u limits
函数中编写相同的功能

后者可能会起作用,但将相同的代码片段埋藏在两个不同的函数中似乎很笨拙,我希望避免这种情况

是否可以从Selectwidget回调我的reset\u plot函数,或者我只需在change\u limits函数中编写相同的功能

Bokeh服务器回调与任何其他python函数都没有区别,它们本身可以被调用,或者调用其他函数,调用方式与任何其他上下文完全相同。在这种情况下,听起来您应该将公共代码分解为您自己的“clear”函数,然后两个回调都可以调用它