hello,
Attempting to grasp some control on the callbacks, I become really confused and i believe at the origin of some of the mess in my program.
The simple example below illustrates the problem: Callbacks are called sometimes and at unexpected times.
I have no idea what could be done to circumvent this problem, and if this should be qualified as a bug
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
def cb(attr,old,new):
print(‘source’,attr,old[‘x’][0],’ → ',new[‘x’][0])
source = ColumnDataSource(dict(index=[0], x=[False]))
source.on_change(‘data’,cb)
b = Button(width=100)
def button_cb():
new = not source.data[‘x’][0]
print(‘patch’,new)
source.patch({ ‘x’: [(0,new)] })
time.sleep(1)
print()
b.on_click(lambda: button_cb())
data_table = DataTable(source=source, width=100, columns=[TableColumn(field=“x”, title=“x”)])
curdoc().add_root(column(b,data_table))
Quickly hitting two and then three times the button, one gets (notice the 2 delayed callbacks after hitting the button three times):
patch True
source data True → True
patch False
source data False → False
patch True
source data True → True
patch False
source data False → False
patch True
source data True → True
source data True → False
source data False → True