I’m currently producing an html page that plots some time-series data. I have added a DateRangeSlider and a CustomJS callback that allows a user to sub-set the data. I would like to perform some calculations on this subset then update the plots with the results. If I want this to remain a standalone html page is my only option to perform the calculations in the JavaCript code of the CustomJS callback?
Yes, that’s exactly right.
postamble template block like I demonstrated it here.
So if you name your file
callbacks.js and put it in
static/js folder you can include it in the template like this (assuming you generate the HTML file from Python):
"""<script>""" + open(os.path.join(os.path.dirname(__file__), "static", "js", "callbacks.js")).read() + """</script>"""
Then if you write there in
callbacks.js a function called
data_range_slider_callback(slider) you could call it in the Bokeh JS callback like this:
Also anywhere in your external JS code if you need any Bokeh model you can get it using:
Bokeh.documents.get_model_by_name('model_name') provided that you gave a
name to your Bokeh widget or glyph like:
button = Button(label='Update', name = 'update_button')
The above assumes you have only one Bokeh
document in your app.
Thanks for the suggestion but I think I’d be out of my depth trying this in JS. I guess I’ll have to make do with launching a bokeh server if I can figure out how to get my callbacks working.