All,
I have recently started using bokeh and I wold like to do the following, I run the following code, which I have found in the example folder of the anaconda distribution.
Once the html file is displayed and I can move the slider, I would like to grab the current value where the slider is at and use it later in the code. At first, I thought to use a parser like pyquery, but as I looked at the source file of the html file, I couldn’t really figure out how to do that. Is there a way I can do that, that is, is there a simple way I can grab the value the slider sits at and feed it back to my python code ?
Thanks for any help,
Giuseppe
from bokeh.io import vform
from bokeh.models import ColumnDataSource, Slider
from bokeh.plotting import figure, output_file, show
from bokeh.models.actions import Callback
import os
import json
os.chdir(“c:\anaconda\rfpack\sipi\primitive”)
output_file(“callback.html”)
x = [x*0.005 for x in range(0, 200)]
y = x
source = ColumnDataSource(data=dict(x=x, y=y))
plot = figure(plot_width=400, plot_height=400)
plot.line(‘x’, ‘y’, source=source, line_width=3, line_alpha=0.6)
callback = Callback(args=dict(source=source), code="""
var data = source.get(‘data’);
var f = cb_obj.get(‘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”, callback=callback)
layout = vform(slider, plot)
show(layout)