I am able to update GeoJSONDataSource using bokeh CustomJS, however, when using periodic_callback, I can't use CustomJS as the callback function. Below is my code with the error message "TypeError: 'CustomJS' object is not callable"
current_year = 1800
n_slider = Slider(start=1, end=50, value=1, step=1, title="N")
toggle = Toggle(label="Play", button_type="success")
callback = CustomJS(args=dict(source=source, year=current_year, n_slider=n_slider, toggle=toggle), code="""
data = source.data;
console.log(toggle.active)
console.log(n_slider.value)
console.log(year)
year = year +1
// edit GeoJSONDataSource
source.change.emit();
""")
curdoc().add_root(column(p, n_slider, toggle))
curdoc().add_periodic_callback(callback, 1000)
My question is,
Is it possible to use a CustomJS as the callback function of periodic_callback, if not, how can I edit the GeoJSONDataSource entry using the normal python function?
It is not possible,
add_periodic_callbackcan only run actual Python callbacks (in a Bokeh server application). There is no built-in facility to executeCustomJScallbacks on a set interval. It would be "hacky" but it's possible theAjaxDataSourcewith its polling interval could be slightlky abused to achieve a similar effect, though.