Accessing values in column data source

Hello,
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 bokeh.events 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))

x=[0.4,0.1,0.2,-0.2,0.5,0.6,-0.3]
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 = sr1.data['x'];
    var d1y = sr1.data['y'];
    var dd1x = d1x.map(x => x *2);
    var dd1y = d1y.map(y => y *2);
    sr1.data['x'] = dd1x;
    sr1.data['y'] = dd1y;

    var absdd1x = dd1x.map(x => Math.abs(x));
    var absdd1y = dd1y.map(y => 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++) {
        srx.data['s'][n] = maxxy * -1;
        srx.data['e'][n] = maxxy;
    }
    console.log(srx.data);
    srx.change.emit();
    sr1.change.emit();
"""  )  

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(srx.data('s')[0], srx.data('e')[0])  # This doesn't work
td1.y_range = Range1d(srx.data('s')[0], srx.data('e')[0])  # This doesn't work 

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

show(row(td1, button))

@RobM

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 srx.data 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