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.
The above answer by birdsarah is correct up to bokeh version 0.12.16 but as of bokeh version 0.13 you need to slighty change the on_change method to make it work:
source = ColumnDataSource(mpg)
columns = [....]
data_table = DataTable(source=source, columns=columns)
def callback(attrname, old, new):
selectionIndex=source.selected.indices[0]
print("you have selected the row nr "+str(selectionIndex))
source.selected.on_change('indices', callback)
I believe that selecting a row of a data table is the same as making a selection on 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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With