I'm trying to have a DataTable which will run a callback when the user press on a certain row. The call back need to have the value of the first column (for the selected row).
Tried few things but non of them worked:
from bokeh.layouts import widgetbox, row, column
from bokeh.models import ColumnDataSource, CustomJS
from bokeh.models.widgets import Button, RadioButtonGroup, RadioGroup, Tabs, \
TextInput, Panel, Div, Select, DataTable, TableColumn, DateFormatter, \
Slider
from bokeh.plotting import curdoc, show
import db_lib # database interaction
import dataAnalyzer
testBox = TextInput(title="test box", value = "start text")
# getting the data here:
data = {}
data["patients"] = {'kyma PT #': [1297, 1301, 1305, 1312], 'client PT #': [15072, 15255, 15228, 15077], 'patient name': ['John', 'David', 'Mark', 'Martin']}
patients_col = [
TableColumn(field="kyma PT #", title="Kyma PT #", width = 50),
TableColumn(field="client PT #", title="Client PT #", width = 50),
TableColumn(field="patient name", title="Patient Name", width = 200),
]
patients_src = ColumnDataSource(data["patients"])
# method 1
source_code = """
row = cb_obj.indices[0]
testBox.update(value=patients_src.data["kyma PT #"][row])
"""
callback = CustomJS(args = dict(source = patients_src), code = source_code)
patients_src.selected.js_on_change('indices', callback)
layout = column(testBox)
show(layout)
This one displays an error: "Instance of 'Instance' has no 'js_on_change' member", it runs without crash but selecting in the table does nothing. Also tried:
# method 2
def table_select(attr, old, new):
testBox.update(value=patients_src.data["kyma PT #"][row])
patients_src.selected.on_change('indices', table_select)
Same thing as the first attempt. And:
# method 3
def table_select(attr, old, new):
testBox.update(value=patients_src.data["kyma PT #"][row])
patients_src.on_change('selected', table_select)
No error here, but the callback does not run.
Worth noting that I'm also running it on server (curdoc()), but the outcome is the same. Any ideas what I'm doing wrong here?