Hi
I am trying to extract data from a columndatasource in order to do send it to another app after interactively changing with javascript.
I created a created a scatter plot that I can interactive create a trendline through the data. I would like the trendline results in a different application. I am able to send data to it but I can’t seem to get the final trendline data out of the columndatasource.
Here is an example, I modified the slider code from bokeh. I added scatter points and can use the slider to see the best-fit exponent.
I want to extract the ‘y’ data to another app. I tried
bestfit = source.data[‘y’]
but the data is not updated as y changes.
I am looking forward to your suggestions
Thanks
Darren
from bokeh.layouts import column
from bokeh.models import CustomJS, ColumnDataSource, Slider
from bokeh.plotting import Figure, output_file, show
import numpy as np
output_file(“js_on_change.html”)
scx = np.arange(0,1,.005)
scy = np.power(scx,3.5)
x = [x*0.005 for x in range(0, 200)]
y = x
source = ColumnDataSource(data=dict(x=x, y=y,scx=scx,scy=scy))
plot = Figure(plot_width=400, plot_height=400)
plot.scatter(‘scx’,‘scy’,source=source,color=‘red’,size=3)
plot.line(‘x’, ‘y’, source=source, line_width=3, line_alpha=0.6)
bestfit = source.data[‘y’]
plot.line(x,bestfit,color=‘green’, line_width=2)
callback = CustomJS(args=dict(source=source), code="""
var data = source.data;
var f = cb_obj.value
x = data[‘x’]
y = data[‘y’]
for (i = 0; i < x.length; i++) {
y[i] = Math.pow(x[i], f)
}
source.trigger(‘change’);
“”")
slider = Slider(start=0.1, end=4, value=1, step=.1, title=“power”)
slider.js_on_change(‘value’, callback)
layout = column(slider, plot)
show(layout)