Hi, I’m trying to fire a js callback from a change in the cds.data. From my understanding you need to replace it entirely for it to work, which I thought I’m doing, but it doesn’t appear to work for me. A python callback off the same cds is working however. This is running on a bokeh server, and with bokeh 2.3.0
I just replied to an older thread about it (apologies), which was similar but not quite the same where the changes were in-place (CDS.js_on_change not called, but CDS.on_change is - #4 by Bryan).
Any help on what I’m doing wrong gratefully received. Thanks.
from bokeh.models import ColumnDataSource
from bokeh.io import curdoc
from bokeh.layouts import layout
from bokeh.models import Button
from bokeh import events
from bokeh.models.callbacks import CustomJS
def bkapp(doc):
### set up dummy cds and a button
cds_counter=ColumnDataSource(data={"counter":[0]})
button_dummy=Button(label="Test Button_dummy", button_type="success", width=60)
### callback for the button, to update the cds
global dummy_int
dummy_int=0
def button_callback(event):
print("button has been pressed")
global dummy_int
dummy_int +=1
temp=dummy_int
cds_counter.data={"counter": [temp]}
print(cds_counter.data["counter"])
button_dummy.on_click(button_callback)
### callbacks I'd like to trigger after pressing the button, via the cds change
js_counter_callback = CustomJS(args=dict(cds_counter=cds_counter), code="""
console.log("test test test is not running")
console.log(cds_counter.data["counter"])
""")
def py_counter_callback(attr, old, new):
print("should run when counter in cds changes??")
cds_counter.on_change("data", py_counter_callback)
cds_counter.js_on_change("data", js_counter_callback)
doc.add_root(layout(button_dummy))
global doc
doc = curdoc()
bkapp(doc)