BokehJS: Callback on selected changed

Hi all,

I’m currently looking into BokehJS and simply cannot find out, how to bind a callback to a selection
event. In python one could do something like that:

source.selected.js_on_change('indices', CustomJS(args=dict(source=source), code="""
        console.log("Hello selection!")
    """)
)

This doesn’t seem to work in BokehJS, because js_on_change is undefined.
So my questions are the following:

  • What’s the intended way of doing this in BokehJS?
  • Is there the possibility to bind javascript functions directly to a callback instead of using a CustomJS?

Thanks in advance!

Cheers,
Gaudenz

And here my script:

It would be source.selected.change.connect(callback) where callback accepts two arguments and the second one is an instance of Selection.

Note also that you usually don’t need to create CustomJS directly in JS code. Instead, you can just use {execute: callback} where callback is a regular function.

Perfect, thanks a lot!

I added the updated code to the gist if anybody is interested: