Skip to content

Instantly share code, notes, and snippets.

@wakita
Last active September 5, 2020 02:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wakita/ad3613b0fe4189016c192a6ae1c07233 to your computer and use it in GitHub Desktop.
Save wakita/ad3613b0fe4189016c192a6ae1c07233 to your computer and use it in GitHub Desktop.
Jupyter notebook のなかで periodic callback を動かす実験
from bokeh.io import output_file, output_notebook, show
from bokeh.models import *
from bokeh.layouts import *
output_notebook()
n = 0
animate_cb = None
def plot(doc):
button = Button(label='Foo', button_type='success')
def animate_update():
global n
button.label = f'Foo (n = {n})'
n = n + 1
def animate():
global animate_cb
animate_cb = doc.add_periodic_callback(animate_update, 1000) if (animate_cb is None) else doc.remove_periodic_callback(animate_cb)
button.on_click(animate)
doc.add_root(button)
show(plot)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment