☰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

Pass arbitray json to CustomeJS

Community Support
AlainD
AlainD

Currently you can pass any data to a CustomeJS as long as it implements a bokeh,model.The most flexible model is the ColumnDataSource which can contain a dict in the form {key: array_of_number,…}.

Is it possible to pass arbitrary json of the form {key: python-dict(),…} in order to serialize it into a {key : json-object} ?

⌁   Link to post
p-himik
p-himik

Yes, it is possible.

from bokeh.io import show
from bokeh.models import Button, CustomJS

b = Button()
b.js_on_click(CustomJS(args=dict(message='hello',
                                 params=dict(a=1, b=2)),
                       code='console.log(message, params)'))

show(b)
⌁   Link to post
AlainD
AlainD

Thanks, it works.

For interested readers, I was talking about more sophisticated data like

data = {'2019' : {'M':10, 'F':12}, '2020' : {'M':11, 'F':13}}

and confused by the fact that ColumnDataSource(data) is invalid.

However, as suggested:

data = {'2019' : {'M':10, 'F':12}, '2020' : {'M':11, 'F':13}}
b.js_on_click(CustomJS(args=dict(message='hello',
                                 params=data,
                       code='console.log(message, params)'))

is a perfectly valid code.

⌁   Link to post
Bryan
Bryan

ColumnDataSource contains only columns, i.e. it is always a mapping of names to arrays (analogous to a Pandas Dataframe)

⌁   Link to post
AlainD
AlainD

The confusion came from the sentence from the Javascript Callback section of the User Guide saying " CustomJS also accepts an args property that maps string names to Bokeh models. Any Bokeh models that are configured in args (on the “Python side”) will automatically be available to the JavaScript code by the corresponding name."

So I was then under the impression that anything that could be passed in args must be encapsulated in a bokeh.model (foe example a DataSourceColumn).

I should have also read the Reference, saying “A mapping of names to Python objects. In particular those can be bokeh’s models…”.

May I suggest a change in the User Guide : " CustomJS also accepts an args property making available Python objects to the Javascript code. In particuler, any Bokeh models that are…"

⌁   Link to post

End of archived discussion · Replies are disabled