Control the jitter width with a CustomJS callback

Hi there,

Is it possible to dynamically change a jitter width with a widget? I tried
few different ways to link a slider.value to a jitter.width without
success. I was expecting slider.js_link("value", jitter, "width") to work,
or using a simple CustomJS callback to do the job but all my attempts

A minimal non-working example with some tested callbacks is available below.

Thanks for your help.

import bokeh.layouts as bl
import bokeh.models as bm
import bokeh.plotting as bp
import bokeh.transform as bt
from bokeh.sampledata.iris import flowers

x = "petal_length"
y = "species"

source = bm.ColumnDataSource(flowers)
y_factors = sorted(flowers[y].unique())
y_range = bm.FactorRange(factors=y_factors)

slider = bm.Slider(title="Jitter width", value=0.5, start=0, end=1, step=0.1)
jitter = bm.Jitter(width=slider.value, range=y_range)

p = bp.figure(y_range=y_range)
r =, y=bt.transform(y, jitter), size=8, source=source,)
p.xaxis[0].axis_label = x
p.yaxis[0].axis_label = y

dashboard = bl.row(p, slider)

# slider.js_link("value", jitter, "width")

# callback_code = """
# r.glyph.y.transform.width = cb_obj.value;
# r.glyph.change.emit();
# """
# callback = bm.CustomJS(args={"r": r}, code=callback_code)
# slider.js_on_change("value", callback)

# callback_code = """
# jitter.width = width;
# r.glyph.change.emit();
# """
# callback = bm.CustomJS(args={"jitter": jitter, "r": r}, code=callback_code)
# slider.js_on_change("value", callback)

callback_code = """
jitter.width = cb_obj.value;
callback = bm.CustomJS(args={"jitter": jitter, "source": source}, code=callback_code)
slider.js_on_change("value", callback)

Hi @loikisan I had to do some digging in the code, but this really should work with some of the versions you have above as well as some that I tried on my own. I think you have uncovered a bug and unfortunately I don’t have a good workaround at present. Please file a GitHub issue with these details.

Hi @Bryan, thanks for your message. I filed this Github issue for reference.

1 Like