hello,
with the little example below, i’d like to ask for the good practice to catch a change in cds in its attached callback.
Here patching (unless you hit the button very quickly) results in old and new dictionaries being the same.
So, how do we actually catch the changes ? (I naively expected this to be between old and new dictionaries)
Do we have to make some bookkeeping of the previous cds data so to be able to find the cds changes between the old and the new data ?
Hopefully there is a better way.
Thanks !
import numpy as np
import time
from bokeh.io import curdoc
from bokeh.layouts import column
from bokeh.models import ColumnDataSource
from bokeh.models.widgets import DataTable, TableColumn, Button
source = ColumnDataSource(dict(index=[0,1,2], x=[0,0,0]))
def cb(attr,old,new):
print(‘source’,attr,old[‘x’][0],’ → ',new[‘x’][0])
source.on_change(‘data’,cb)
b = Button()
def button_cb():
new = int(not source.data[‘x’][0])
print(‘patch’,new)
time.sleep(0.1)
source.patch({‘x’: [(0,new)]})
b.on_click(button_cb)
data_table = DataTable(source=source, columns=[
TableColumn(field="x", title="x"),
TableColumn(field="r", title="r"),
], editable=True)
curdoc().add_root(column(b,data_table))