☰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

Python callback from a ColumnDataSource

Community Support
Gilles
Gilles

Hi,
According to Python callback for HoverTool - Community Support - Bokeh Discourse it would be possible to get a python callback on the server when a HoverTool callback is triggered. This is achieved via a ColumnDataSource.

I tried to implement it but the server callback doesn’t get called. The HoverTool JS callback gets triggered and the datasource updated.

I was wondering if the datasource needs to be attached to a renderer.

Please find below a snipet of my code

hover_details_data_source = ColumnDataSource(
    {
        ‘indices’: []
    }
)
hover_details_data_source.on_change(‘data’, on_hover_callback)

code = “”"
    console.log('indices: ’ + cb_data.index.indices)
    const indices = cb_data.index.indices
    if (indices.length){
        data_source.data[‘indices’] = cb_data.index.indices
        data_source.change.emit();
    }
“”"
callback = CustomJS(
    args={
        ‘data_source’: hover_details_data_source
    },
    code=code
)

hover = plot.select(“hover”)
hover.callback = callback

def on_hover_callback(attr, old, new):
    print(‘Here’)
⌁   Link to post
Bryan
Bryan

In order for this Python-side callback to be triggered:

it is necessary for a real, actual assignment to be made to the .data property:

data_source.data = new_data_dict

It is not possible for Bokeh to automatically detect “in-place” changes like you are making above. This is consistent and the same across every Bokeh model and property: actual assignments are what trigger property callbacks.

The change.emit() is not relevant here. That is purely a JS-side function and has no application to Python callbacks.

⌁   Link to post

End of archived discussion · Replies are disabled