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