Is there any way to update Span based on CDS.update? When I’m running this code the location value is fixed and doesn’t change.
line = Span(location=CDS.data['y_data'].mean())
avg = p.add_layout(line)
Is there any way to update Span based on CDS.update? When I’m running this code the location value is fixed and doesn’t change.
line = Span(location=CDS.data['y_data'].mean())
avg = p.add_layout(line)
If your code is not in a Python or a JavaScript callback, than it won’t be run again if you somehow interact with the page (unless you’re using bokeh serve
and just refresh the page).
The easiest and the most versatile way to do what you want is with JavaScript callbacks: JavaScript callbacks — Bokeh 2.4.2 Documentation
Same limitations to Arrow, right? Or am I doing something wrong?
Same limitations on any Bokeh model. You cannot re-run any Python code without callbacks and without using bokeh serve
.
Ok, so what’s wrong here? Both plots (Arrow, segment) take same CDS. Segment is updated correctly, Arrow, not. For simplicity I don’t show CDS, but as I mentioned, it’s being updated correctly.
def plot_circle():
name = 'p_circle'
p = figure(frame_width=300, frame_height=300, match_aspect=True,
x_range = Range1d(start=-1.1, end=1.1, bounds = (-1.1, 1.1)), y_range = Range1d(start=-1.1, end=1.1, bounds = (-1.1, 1.1)),
name=name)
p.segment(x0=0, y0=0, x1='plot_x', y1='plot_y', source=CDS_variables, line_width=3, alpha=0.5)
p.add_layout(Arrow(end=VeeHead(size=10, line_color=None), line_width=1.5,
x_start=0, y_start=0, x_end='plot_x', y_end='plot_y', source=CDS_variables))
return p
plot_3 = plot_circle()
def xaxis_callback(attrname, old, new):
x_new = select_xaxis.value
CDS_variables.data.update({'plot_x': CDS_variables.data[x_new] })
def yaxis_callback(attrname, old, new):
y_new = select_yaxis.value
CDS_variables.data.update({'plot_y': CDS_variables.data[y_new] })
select_xaxis.on_change('value', xaxis_callback)
select_yaxis.on_change('value', yaxis_callback)
curdoc().add_root(plot_3)
Two things:
Sorry for mixing topics. W’ll be waiting for the solution.
It was just merged into master, so the next published dev/rc/release version should have the fix.