我有一个简单的散景应用程序,可以创建一个绘图并将其插入到Jinja模板中。
import io
from jinja2 import Template
from bokeh.embed import components
from bokeh.models import Range1d
from bokeh.plotting import figure
from bokeh.resources import INLINE
from bokeh.util.browser import view
template = Template("""
<html>
<head>
<title>Bokeh with Jinja example</title>
{{ js_resources }}
{{ css_resources }}
{{ script }}
</head>
<body>
<h1>This is a test</h1>
{{ myplot['myplot'] }}
</body>
</html>
""")
# The plot
TOOLS="pan,wheel_zoom,box_zoom,reset,save"
x1 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
y1 = [0, 8, 2, 4, 6, 9, 5, 6, 25, 28, 4, 7]
xr1 = Range1d(start=0, end=30)
yr1 = Range1d(start=0, end=30)
p1 = figure(x_range=xr1, y_range=yr1, tools=TOOLS, plot_width=300, plot_height=300)
p1.scatter(x1, y1, size=12, color="red", alpha=0.5)
js_resources = INLINE.render_js()
css_resources = INLINE.render_css()
plots = {'myplot': p1}
script, div = components(plots)
print div.keys()
html = template.render(js_resources=js_resources,
css_resources=css_resources,
script=script,
myplot=div)
filename = 'embed_multiple.html'
with io.open(filename, mode='w', encoding='utf-8') as f:
f.write(html)
view(filename)
问题是:我需要定期(每5秒钟)重新读取数据(x1)并重新绘制图表以显示更新图表。
我该怎么做?我阅读了关于流的内容,但我无法使用Jinja模板实现它们。
提前致谢, 詹卢卡