我有一个用 Python 编写的 Web 应用程序 - Flask。当用户在其中一个页面(POST 请求)中填写一些设置时,我的 Controller 计算一些函数并使用 Bokeh 和以下命令绘制输出,然后我重定向到 Bokeh 创建的 HTML 页面。
output_file("templates\\" + idx[j]['name'] + ".html", title = "line plots")
TOOLS="resize,crosshair,pan,wheel_zoom,box_zoom,reset,box_select,lasso_select"
p = figure(tools=TOOLS, x_axis_label = 'time', y_axis_label = 'L', plot_width = 1400, plot_height = 900)
我的所有 HTML 页面都扩展了我的“Template.HTML”文件,除了 Bokeh 生成的那些。我的问题是如何自动修改 Bokeh 生成的 HTML 文件以扩展我的 template.html 文件?这样,我的所有导航栏和超大屏幕都位于 Bokeh html 文件之上。
{% extends "template.html" %}
{% block content %}
<Bokeh.html file>
{% endblock %}
最佳答案
在这种情况下,您不想使用 output_file
。 Bokeh 有一个专门用于嵌入到 Web 应用程序中的 HTML 模板的功能,bokeh.embed.component
,在 quickstart 中进行了演示。和 tutorial .
from bokeh.embed import components
script, div = components(plot)
return render_template('page.html', script=script, div=div)
<body>
{{ div|safe }}
{{ script|safe }}
</body>
Here is a complete, runnable example that that shows how to use this with Flask.
关于python - 将 "Bokeh created html file"嵌入到 Flask "template.html"文件中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33398950/