Python Flask应用程序与交互式散景图 [英] Python Flask App with Interactive Bokeh plots
问题描述
p
pre>我有一个Flask应用程序,其中我的图是使用Bokeh在控制器python代码中用下面的命令创建的。 = figure(tools = TOOLS,x_axis_label ...)
p.line(....)
script,div = components(p)
而我传递script& div元素到我的HTML页面使用:
$ b $ pre $render_template(.html,script = script,div = div)
我想在图上添加一个交互式滑块。
slider = Slider(start = 0, = $ = $,$ = $,$ = $,$ = $,$ = $,$ =第一个问题是,我怎么能把滑块信息的组件功能,以生成正确的脚本和div元素,我可以传递给我的HTML文件?
我的第二个问题是:在滑块上有一个值,我怎么能把它发回我的控制器来更新我的情节,并发送新的div和脚本元素到HTML文件来更新我的情节?
我真的很感激你能否解释必要的步骤来达到这个解决方案。
解决方案回答下面的第一个问题:
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)})
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.
解决方案 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)})
这篇关于Python Flask应用程序与交互式散景图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!