Setting start and end of x_range in javascript locks x panning


I’m trying to dynamically modify the x_range of a plot based on a subset of the data that I’m plotting. I’m using a javascript callback for this.

The result is that the x_range is set correctly, but I cannot pan or zoom on the x_range. If I set the range on python instead of Javascript, I don’t see this issue.

I’ve checked (with console.log) that the bounds, max_interval, and min_interval attributes of x_range are all null, but I’ve also tried to set them manually to null in the javascript call with same results.
Here’s a minimal working example, tested in 1.4.0 and 2.2.1:

import bokeh as bk
from bokeh.models import CustomJS

from bokeh import  plotting
from bokeh.plotting import figure, output_file, show

# prepare some data
x = [1, 2, 3, 4, 5]
y = [6, 7, 2, 4, 5]

# output to static HTML file

# create a new plot with a title and axis labels
p = figure(title="simple line example", x_axis_label='x', y_axis_label='y')

# add a line renderer with legend and line thickness
p.line(x, y, legend_label="Temp.", line_width=2)
callback = CustomJS(args=dict(xr=p.x_range),
            xr.start = 0;
            xr.end = 3;
p.x_range.js_on_change('start', callback)
# This produces the expected behavior, but doesn't allow to modify the x_range on change
# p.x_range.start = 0
# p.x_range.end = 3
#show the results

Is this behavior expected? How can I unlock panning on the x axis?

Actually, now that I think of it, I guess me trying to pan might be triggering the callback, and that’s why the range doesn’t change?

Your code basically says: “On each change to x_range, reset it back to (0, 3)”.

Ah, yeah, that’s what I thought. Thanks. I’ll have to link the callback to a different event.