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
failed.
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 = p.circle(x=x, 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;
source.change.emit();
"""
callback = bm.CustomJS(args={"jitter": jitter, "source": source}, code=callback_code)
slider.js_on_change("value", callback)
bp.show(dashboard)