Hi,
The UI has a time slider and a play button. I am trying to take the specific time when user click pause but I am not sure how to retrieve the value outside the animate() function.
Really appreciate your time and help!
import math
from bokeh.io import save, curdoc
from bokeh.layouts import column, row, gridplot
from bokeh.model import Model
from bokeh.models import CustomJS, Slider, Callback, HoverTool, Button
from bokeh.plotting import ColumnDataSource, figure, show
from bokeh.models.widgets import Panel, Tabs
import numpy as np
import pandas as pd
t0, tf = 0.0, 43200.0 # 12hrs
N = 25
tspan = np.linspace(t0, tf, N)
time_step = tspan[1]
slider_time = Slider(title="Time Slider (s)", value=t0, start=t0, end=tf, step=time_step, width=300)
def animate_update():
current_time = slider_time.value + time_step
if current_time > tf:
current_time = t0
slider_time.value = current_time
def animate():
global callback_id
if animate_button.label == '► Play':
animate_button.label = '❚❚ Pause'
callback_id = curdoc().add_periodic_callback(animate_update, 1*450.0) # s to milliseconds conversion
else:
animate_button.label = '► Play'
curdoc().remove_periodic_callback(callback_id)
animate_button = Button(label='► Play', width=80)
animate_button.on_event('button_click', animate)
layout = (column(slider_time, animate_button))
curdoc().add_root(layout)