☰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

How can I add a standalone CustomJS callback without attaching it to any model?

Community Supportcustomjs
Sandra_Winkelberry
Sandra_Winkelberry

Hello everyone,

I want to call a CustomJS callback from the html document, but when I initialize it in python, it doesn’t show up in the html file it’s creating.
For example, I initialize the callback in Python, it gives me the id in the command line, but does not include it in the html

CustomJS(args=dict(source1=source1, source2=source2), name="foo", code="""
    //do something
""")

CustomJS(id = ‘1344’, …)

Is there any solution or workaround to this?

Thank you
Sandra

⌁   Link to post
Sandra_Winkelberry
Sandra_Winkelberry

I work with bokeh and flask and want to automatically load my csv data (ColumnDataSource) when the webpage is loaded

<script>
  window.onload = function(){
    window.Bokeh.documents[0].get_model_by_name(“foo”).execute();
  }
</script>

This CustomJS callback would call a python function via ajax to fetch the data and update the ColumnDataSource in the CustomJS callback.

If this isn’t possible I may have an idea for a workaround.
I thought it might be possible to assign the callback to a model and then make it invisible or something like that. But I dont know if there exists a model that can be set like this.

⌁   Link to post
Bryan
Bryan

Althought it’s unusual, you might be able to add the CustomJS as a root itself with curdoc().add_root(...) (even in standalone content). But I can’t guarantee that will work, you will just have to try. Otherwise, you can add it to an some other model as a workaround, as you suggest. (A DataModel might be a good choice)

⌁   Link to post

End of archived discussion · Replies are disabled