MRocklin MRocklin - 3 months ago 156
Python Question

Trigger event when Bokeh DataTable Selection

Is it possible to trigger a callback event when I select a row (or rows) of a Bokeh

DataTable
?

def update(rows):
...

dt = DataTable(...)
dt.on_select(update)


I see that there is an
.on_change
method that can trigger on a particular property, however I can not find a property that corresponds to the selected rows.

Answer

I believe that selecting a row of a data table is the same as making a selection a data source. So, if you attach a callback to the datasource powering the table then the callback should work.

source = ColumnDataSource(mpg)
columns = [....]
data_table = DataTable(source=source, columns=columns)
source.on_change('selected', callback)