Last active
September 5, 2020 02:08
-
-
Save wakita/ad3613b0fe4189016c192a6ae1c07233 to your computer and use it in GitHub Desktop.
Jupyter notebook のなかで periodic callback を動かす実験
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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