Pass arbitray json to CustomeJS

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} ?

Yes, it is possible.

from import show
from bokeh.models import Button, CustomJS

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


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}}
                       code='console.log(message, params)'))

is a perfectly valid code.

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

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…"

@AlainD Please open an issue (or a PR) any suggestions only made here are likely to get lost.