Accessing values in column data source

I am trying to update the a figures x_range and y_range from values generated during a CustomJs callback and stored in a ColumnDataSource. I’m stuck with how to access and use select values from the ColumnDataSource. I think this example code replicates my probelm, it fails with TypeError: ‘PropertyValueColumnData’ object is not callable

from bokeh.plotting import figure, show
from bokeh.models import ColumnDataSource, CustomJS, Button, Range1d
from import ButtonClick
from bokeh.layouts import row

button = Button(label='multiply by 2')
s = [-1, -1]
e = [1, 1]
srx = ColumnDataSource(data=dict(s=s, e=e))

y = [-0.7,0.3,-0.3,0.6,0.2,0.2,0.1]
sr1 = ColumnDataSource(data=dict(x=x, y=y))  

callback = CustomJS(args=dict(srx=srx, sr1=sr1), code="""

    var d1x =['x'];
    var d1y =['y'];
    var dd1x = => x *2);
    var dd1y = => y *2);['x'] = dd1x;['y'] = dd1y;

    var absdd1x = => Math.abs(x));
    var absdd1y = => Math.abs(y));
    var maxx = Math.max(...absdd1x);
    var maxy = Math.max(...absdd1y);
    var maxxy = Math.max(maxx, maxy);
    for (var n = 0; n <= 1; n++) {['s'][n] = maxxy * -1;['e'][n] = maxxy;
"""  )  

button.js_on_event(ButtonClick, callback)

td1 = figure(plot_width=300, plot_height=300, title='Target', 
        x_axis_label='x', y_axis_label='y')

td1.x_range = Range1d('s')[0],'e')[0])  # This doesn't work
td1.y_range = Range1d('s')[0],'e')[0])  # This doesn't work 

td1.axis[0].fixed_location = 0
td1.axis[1].fixed_location = 0'x', y='y', source=sr1, size=7)

show(row(td1, button))


Check the syntax of the lines that you’ve highlighted as not working.

Upon inspection, i.e. not actually trying to run and reproduce the error, it looks like it is due to the fact that you’re accessing the dictionary with parens () which Python is interpreting as a callable (function or method). You should be using brackets [] here.

Ah, yes well spotted. That fixes the error but the values aren’t being picked up by the axis. I’m guessing x_range needs to “know” it’s menat to be getting it’s values from a source but I can’t specify this in Range1d. I thought I might need to use somethng like,

td1.x_range.js_on_event('start', callback)
td1.x_range.js_on_event('end', callback)
td1.y_range.js_on_event('start', callback)
td1.y_range.js_on_event('end', callback)

but this just seems to result in the autoscaling