Python 3.x 如何为bokeh中的动画实现开始-停止按钮/播放恢复按钮?

Python 3.x 如何为bokeh中的动画实现开始-停止按钮/播放恢复按钮?,python-3.x,animation,widget,bokeh,Python 3.x,Animation,Widget,Bokeh,我正在尝试为bokeh动画实现一个星形停止按钮。我将bokeh服务器与curdoc()函数结合使用,但到目前为止,我还没有取得太多成功 我想知道一个更有经验的人会怎么做 谢谢给你。使用bokeh serve运行——show app.py(在bokeh v1.0.4上测试) 结果: from bokeh.models import ColumnDataSource, Toggle, Column from bokeh.plotting import figure, curdoc from dat

我正在尝试为bokeh动画实现一个星形停止按钮。我将bokeh服务器与curdoc()函数结合使用,但到目前为止,我还没有取得太多成功

我想知道一个更有经验的人会怎么做


谢谢

给你。使用bokeh serve运行——show app.py(在bokeh v1.0.4上测试)

结果:

from bokeh.models import ColumnDataSource, Toggle, Column
from bokeh.plotting import figure, curdoc
from datetime import datetime
import random

source = ColumnDataSource(dict(time = [datetime.now()], value = [random.randint(5, 10)]))
plot = figure(plot_width = 1200, x_axis_type = 'datetime', tools = 'pan,box_select,crosshair,reset,save,wheel_zoom')
plot.line(x = 'time', y = 'value', line_color = 'black', source = source)
toggle = Toggle(label = "Toggle", button_type = "success")

def update():
    if toggle.active:
        source.stream(dict(time = [datetime.now()], value = [random.randint(5, 10)]))

curdoc().add_root(Column(plot, toggle))
curdoc().add_periodic_callback(update, 1000)