Bokeh data table selection event not working after version upgrade 1.0.0

Viewed 301

After bokeh version 1.0.0 upgrade I get not subscriptable error on data table row click. This was working perfectly fine with version 0.13 Details below :

Code snippet :

tblSource.selected.on_change('indices', table_select_callback) 


def table_select_callback(attr, old, new):

    try:
        selected_index = tblSource.selected["1d"]["indices"][0]
        selectedId = str(tblSource.data["idList"][selected_index])

        print(selectedId)
    except IndexError:
        pass

ERROR

2018-10-25 10:18:19,784 error handling message Message 'PATCH-DOC' (revision 1) content: {'events': [{'kind': 'ModelChanged', 'model': {'type': 'Selection', 'id': '4937'}, 'attr': 'indices', 'new': [2]}], 'references': []}: TypeError("'Selection' object is not subscriptable",)
1 Answers

This usage with the "dict" was deprecated several releases ago. All outstanding deprecations were completed for the 1.0 release. Starting with version 1.0 the correct and supported way of reading or writing selections is to access the named properties on the Selection object, e.g

selected_index = tblSource.selected.indices[0]

This usage is now maintained under CI testing, and will be the correct way to access selections for any 1.x release.

Related