extract data from columndatasource

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)

To be clear, you are trying to get the updated values in real *python* code, not in JS code? If so, you will have to run a Bokeh server application. Once a standalone Bokeh document (e.g. those created with "output_file") are created and shown, they run *entirely* in the browser from that point on. There is NO persistent or continued connection to any python instance. (i.e., your script below runs, generates HTML, and then exits, immediately.) The purpose of the Bokeh server is precisely to provide this kind of two-way synchronization between the BokehJS in the browser, and real running python code.

You can find out more about Bokeh server apps here:

  http://bokeh.pydata.org/en/latest/docs/user_guide/server.html

Thanks,

Bryan

···

On Apr 29, 2017, at 12:48, Darren Kondrat <[email protected]> wrote:

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)

--
You received this message because you are subscribed to the Google Groups "Bokeh Discussion - Public" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/CAPTrt5bkL_mhqGTjcp0xMcMmYu9VBKr4sbO%2BL0qGqDaUtN4hUQ%40mail.gmail.com\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.