patch columndatasource and catch changes


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 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])


b = Button()

def button_cb():

new = int(not[‘x’][0])



source.patch({‘x’: [(0,new)]})


data_table = DataTable(source=source, columns=[

    TableColumn(field="x", title="x"),

    TableColumn(field="r", title="r"),

], editable=True)