5

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.

1

2 Answers 2

13

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) 
Sign up to request clarification or add additional context in comments.

Comments

6

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) 

6 Comments

Will this work in a notebook or does this require an active bokeh server?
This will work in a notebook/html with CustomJS callback. source.callback = CustomJS(code=.....) I'm not aware of server style callbacks working generally in notebooks.
How can you get the selected row data?
bokeh.pydata.org/en/latest/docs/reference/models/… source.data gives you the data dictionary from which you extract the relevant data.
Is this still working? attempted to add a callback on nonexistent DataTable.selected property
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.