☰Read-only archive⌕
Looking for help with Bokeh?

This is a read-only archive. Ask questions and join the conversation on GitHub.

Visit Community Support on GitHub →
Archived discussions · Captured October 28, 2026

Interactive calculations

Community Support
RobM
RobM

Hello,
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?
Thanks,
rob

⌁   Link to post
tony-bony
tony-bony

You can include your own external JavaScript code by specifying it in the 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:

range_slider.js_on_change('value', CustomJS(code='data_range_slider_callback(cb_obj)'))

Also anywhere in your external JS code if you need any Bokeh model you can get it using:
Bokeh.documents[0].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.

⌁   Link to post
RobM
RobM

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.

⌁   Link to post

End of archived discussion · Replies are disabled