如何在python bokeh中对按钮单击执行onclick操作?

如何在python bokeh中对按钮单击执行onclick操作?,python,python-3.x,button,visualization,bokeh,Python,Python 3.x,Button,Visualization,Bokeh,我是bokeh的新手,我有一个关于button onclick事件的问题,下面提供了代码: x = widgetbox(button) show(x) fruits = ['Answered', 'Unanswered','Total'] top1=[1,2,3] def callback(): p = figure(x_range=fruits, plot_height=250, title="sophia bot") p

我是bokeh的新手,我有一个关于button onclick事件的问题,下面提供了代码:

    x = widgetbox(button)
    show(x)
    fruits = ['Answered', 'Unanswered','Total']
    top1=[1,2,3]
    def callback():
        p = figure(x_range=fruits, plot_height=250, title="sophia bot")
        p.vbar(x=fruits, top=top1, width=0.9)
        p.xgrid.grid_line_color = None
        p.y_range.start = 0
        output_file("abc.html")
        show(p)
    button_one = Button(label="Start", disabled=True, callback=callback)
    show(button_one)
但这并不是在执行操作,下面的代码单独使用时,会绘制图形,我希望在单击按钮时图形能够显示出来

    fruits = ['Answered', 'Unanswered','Total']
    top1=[1,2,3]
    p = figure(x_range=fruits, plot_height=250, title="sophia bot")
    p.vbar(x=fruits, top=top1, width=0.9)
    p.xgrid.grid_line_color = None
    p.y_range.start = 0
    output_file("abc.html")
    show(p)

谢谢

您必须将回调分配给按钮,如下所示:

from bokeh.models import Button
from bokeh.io import curdoc

bt = Button(label='Click me')

def change_click():
    print('I was clicked')

bt.on_click(change_click)

curdoc().add_root(bt)
使用
bokeh-service——show example.py
启动此功能

注意:还可以看看我在哪里谈到动态布局