0

I am using bokeh to plot my math functions created with python/numpy.

I would like to use sliders as shown in

http://docs.bokeh.org/en/latest/docs/server_gallery/sliders_server.html

Once I create the html file with the plot, I would like to select different values on the sliders which modify the plot and then read back the chosen values in into python to use it for other manipulations.

What is the best way to read the chosen value on the slider from the html file back into python ?

I saw pyquery could be useful, but I cannot really figure that out.

Any suggestions would be appreciated based on above scenario.

bigreddot
  • 33,642
  • 5
  • 69
  • 122
geppo
  • 1
  • 4

2 Answers2

0

There are two slider examples in the bokeh repo, where the slider is connected back to python via the bokeh server.

If this isn't what you were after, can you elaborate a little more?

birdsarah
  • 1,165
  • 8
  • 20
  • Thanks for your reply, I guess I should elaborate more. It is the Sliders App - first bullet item - what I would like to do is to read the current value that I select by sliding back and forth the cursor of the slider. I thought to use an html parser, but as I open the example as a source code, it wasn't able to locate the value in the page. I suspect I might some more complex extraction commands ... since I am a real beginner, I am not sure. My final goal is to read back into the python code the value selected and use that value for other functions later in the python code. Thanks – geppo Sep 08 '15 at 22:58
  • @geppo, I'm afraid I'm not understanding. The examples do read back in the values from the slider. e.g. https://github.com/bokeh/bokeh/blob/0c78cf646ec95d3c003c714c35a388db4b4ad834/examples/app/sliders_applet/sliders_app.py#L118 - the function has the new value of the slider in argument `new`. – birdsarah Sep 09 '15 at 06:27
  • OK, I think I am not explaining myself well, let me try to copy the code – geppo Sep 09 '15 at 21:23
  • whatever is in he 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) – geppo Sep 09 '15 at 21:24
  • more on the code ---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) – geppo Sep 09 '15 at 21:24
  • Now, if you copy the two sections above, the first one starting from "from bokeh.io" and the secodn one starting from "callback" and you put them together in a py file and execute it, you get an html file with a slider. I would like to be able to grab the value that the slider select and bring it back into the above code... – geppo Sep 09 '15 at 21:26
  • I can't reason about this. Can you update your original question and use syntax highlighting. – birdsarah Sep 10 '15 at 21:58
  • @ birdsarah thank you. It turns out that what I am asking can be done using bokeh-server. "A static HTML file and the state of the slider is inside a web browser and never reflected back to the HTML file. What you should be doing is to use bokeh-server." Thanks. Item closed – geppo Sep 11 '15 at 22:26
0

A static HTML file and the state of the slider is inside a web browser and never reflected back to the HTML file. What you should be doing is to use bokeh-server - answered via bokeh-google group

geppo
  • 1
  • 4