Python Flask App with Interactive Bokeh plots

别说谁变了你拦得住时间么 提交于 2019-11-29 22:38:38

问题


I have a Flask App in which my plots are created using Bokeh in the controller python code with below commands:

p = figure(tools = TOOLS, x_axis_label ...)
p.line(....)
script, div = components(p)

and I pass "script" & "div" elements to my HTML page using:

render_template(.html, script = script, div =div)

I want to add a interactive slider bar on top of my plot. Based on the Bokeh website with the following command, I should be able to do it.

slider = Slider(start=0, end=10, value=1, step=.1, title="Stuff")

So my first question is, how can I put slider information to the components function to generate correct "script" and "div" elements that I could pass it to my HTML file?

My second question is: Having a value on the slider, how can I post it back to my controller to update my plots and send new "div" and "script" elements to the HTML file to update my plots?

I really appreciate if you could explain necessary steps to achieve this solution.


回答1:


Find answer for the first question below:

p.line(.....)
slider1 = Slider(start=0, end = 100, value = y[j] / bth, step = 1, title = "Mag")
slider2 = Slider(start=0, end = 100, value = y1[j] / bth, step = 1, title = "test")
script, div = components({"p": p, "slider1":vform(slider1), "slider2":vform(slider2)})


来源:https://stackoverflow.com/questions/33486522/python-flask-app-with-interactive-bokeh-plots

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!