Bokeh DataTable选择时触发事件

MRo*_*lin 3 python bokeh

当我选择Bokeh的一行(或多行)时,是否可以触发回调事件DataTable

def update(rows):
   ...

dt = DataTable(...)
dt.on_select(update)
Run Code Online (Sandbox Code Playgroud)

我看到有一个.on_change方法可以触发特定属性,但是我找不到与所选行对应的属性.

Jor*_*ris 8

通过birdsarah上述答案是正确的最多的背景虚化版本0.12.16但作为背景虚化版本0.13,你需要略低改变on_change方法,使其工作:

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)
Run Code Online (Sandbox Code Playgroud)


bir*_*rah 6

我认为选择一行数据表与在数据源上进行选择相同.因此,如果您将回调附加到为表提供电源的数据源,那么回调应该可以正常工作.

source = ColumnDataSource(mpg)
columns = [....]
data_table = DataTable(source=source, columns=columns)
source.on_change('selected', callback)
Run Code Online (Sandbox Code Playgroud)