I am passing a ColumnDataSource, which contains references to Bokeh figures, as an argument to a js_on_change function . This works fine if the CDS is static and not changed later on. However if the CDS is updated right before the js code is run, the CDS data seems to become corrupted and will trigger the following JS error. Full example is below. Any idea what is going on here?
Uncaught Error: reference {“id”:“1002”} isn’t known (not in Document?)
from bokeh.io import output_notebook, curdoc
from bokeh.layouts import row, column
from bokeh.plotting import figure
from bokeh.models import ColumnDataSource, CustomJS
from bokeh.models.widgets import Button
p = figure(width=600, height=200, title="Fruit counts by year", tools="save", css_classes=["test"])
button = Button(label="Click me", button_type="success")
plot_cds = ColumnDataSource({})
def trigger_js_change():
plot_cds.data = {"test": [p]} # updating the cds with bokeh models at runtime will trigger an error
button.disabled = True
button.on_click(trigger_js_change)
button.js_on_change("disabled", CustomJS(
args=dict(plot_cds=plot_cds),
code="""
console.log(plot_cds) // triggers error
"""))
curdoc().add_root(column(p, button))