Hello,
Recently updated to 0.13.0 and seem to be running into an issue when trying to use a JS / Python Callback combination attached to the Jupyter Notebook server. I’ve attached a notebook, but for clarities sake, the code is also below. This is intended to be run in Jupyter Notebook.
The objective of the code is to have a JS Callback attached to the x_range and y_range which contains the dimensions of the plot and will update a ColumnDataSource ‘dims’ each time the plot ranges change. The JS code contains a throttle to limit the frequency of callbacks when zooming (this is not my code and has been taken from an example I have since lost track of).
‘dims’ will in turn trigger a python callback which will handle some larger plot changes.
I cannot get the latter python callback to trigger, as everytime I zoom on the plot, I receive the following console error:
VM64 bokeh-0.13.0.min.js:31 Uncaught Error: reference {“id”:“0c0b6f42-4dbb-46e0-9684-c1cb28a23369”,“type”:“ColumnDataSource”} isn’t known (not in Document?)
at o (VM64 bokeh-0.13.0.min.js:31)
at VM64 bokeh-0.13.0.min.js:31
at o (VM64 bokeh-0.13.0.min.js:31)
at Function.P._resolve_refs (VM64 bokeh-0.13.0.min.js:31)
at P.apply_json_patch (VM64 bokeh-0.13.0.min.js:31)
at t._handle_patch (VM64 bokeh-0.13.0.min.js:31)
at t.handle (VM64 bokeh-0.13.0.min.js:31)
at t._steady_state_handler (VM64 bokeh-0.13.0.min.js:31)
at t.ACK.t.msgtype._current_handler (VM64 bokeh-0.13.0.min.js:31)
at t._on_message (VM64 bokeh-0.13.0.min.js:31)
``
The “id” above is referring to the dims Columndatasource object, but I cannot see why it is not considered part of the document (previously I have had this code running effectively with 0.12.6).
Code is below (MVE)
import bokeh.plotting as bk
from bokeh.models import ColumnDataSource, CustomJS
from bokeh.application.handlers import FunctionHandler
from bokeh.application import Application
import numpy as np
bk.output_notebook()
``
class TestPlot():
def init(self):
self.x_range = np.arange(100)
self.y_range = np.arange(100)
self.width = 100
self.height = 100
self.dims = ColumnDataSource(data=dict(width=[self.width],
height=[self.height],
xmin=[self.x_range.min()],
xmax=[self.x_range.max()],
ymin=[self.y_range.max()],
ymax=[self.y_range.min()]))
self.dims_jscode = “”"
var update_dims = function () {
var new_data = {
height: [plot.plot_height],
width: [plot.plot_width],
xmin: [plot.x_range.start],
ymin: [plot.y_range.start],
xmax: [plot.x_range.end],
ymax: [plot.y_range.end]
};
dims.data = new_data;
};
if (typeof throttle != ‘undefined’ && throttle != null) {
clearTimeout(throttle);
}
throttle = setTimeout(update_dims, 100, “replace”);
“”"
self.dims.on_change(‘data’, self.on_dims_change)
self.figure = bk.figure(x_range = (self.x_range.min(),
self.x_range.max()),
y_range = (self.y_range.max(),
self.y_range.min()))
self.figure.x_range.callback = CustomJS(code=self.dims_jscode,
args=dict(plot=self.figure,
dims=self.dims))
self.figure.y_range.callback = CustomJS(code=self.dims_jscode,
args=dict(plot=self.figure,
dims=self.dims))
self.figure.line(np.arange(100), 0.5*np.arange(100))
def on_dims_change(self, attr, old, new):
print(self.dims.data)
def modify_doc(self, doc):
doc.add_root(self.figure)
bk.curdoc().clear()
p = TestPlot()
handler = FunctionHandler(p.modify_doc)
app = Application(handler)
bk.show(app)
``
Any thoughts would be much appreciated!
Kind regards,
George
JupyterCallbackError.ipynb (23.2 KB)