如何在Python Bokeh中执行按键点击时的onclick操作?

2024-05-13 22:30:53 发布

您现在位置:Python中文网/ 问答频道 /正文

我是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)

谢谢


Tags: 代码plottitleshowcallbackrangebuttontotal