Span - how to update location based on CDS

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(['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:

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)),

    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{'plot_x':[x_new] })

def yaxis_callback(attrname, old, new):
    y_new = select_yaxis.value{'plot_y':[y_new] })

select_xaxis.on_change('value', xaxis_callback)
select_yaxis.on_change('value', yaxis_callback)


Two things:

  1. Your latest code block differs from the very first one in a critical way. The first one hardcodes the data. The latest one does not hardcode any data that’s derived from the data source - it just points to the columns. Meaning, if the data in the columns is updated, everything that’s linked with those columns should be updated automatically.
  2. You’re hitting a known bug:

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.