如何将牵牛星图从一条弗拉斯克路线传递到另一条



我对Flask很陌生。我正在开发一个显示图表的网络应用程序。我需要展示的图表之一是使用Altair。

from altair import layer
def create_altair(anomaly_id):
.
.
.
graph = (
layer(interval, All, normals, anomalies, current_anomaly)
.properties(width=870, height=450)
.configure_title(fontSize=20)
)
return graph.to_json(), one_anomaly
@App.route("/anomaly/<int:anomaly_id>", methods=["GET", "POST"])
@login_required
def anomaly(anomaly_id):
graph, current_anomaly = create_altair(anomaly_id)
if """form is valide, it will be input to the database""":
anomaly_id += 1
return redirect(
url_for(
"anomaly",
title="Anomaly Dectection",
anomaly_id=anomaly_id,
form=form,
single_anomaly=current_anomaly,
graph=graph,
)
)
return render_template(
"anomaly.html",
title="Anomaly Dectection",
anomaly_id=anomaly_id,
form=form,
single_anomaly=current_anomaly,
graph=graph,
)

然后我需要把我从异常路线得到的图传给下面的牵牛星图路线。我尝试在URL链接中使用变量(如本文所示(和flask.session,但两者都不起作用。这些方法正确吗?或者还有其他我没有探索过的方法吗?提前谢谢!

########################
# Altair Routes
########################
@App.route("/chart/anomaly/<string:graph>")
def anomaly_chart(graph):
return graph
<!-- Render Charts -->
<script type="text/javascript">
function parse(url, div) {
var opt = {
mode: "vega-lite",
renderer: "svg",
actions: { export: true, source: false, editor: false }
};
vegaEmbed("#" + div, url, opt, function (error, result) {
// result.view is the Vega View, url is the original Vega-Lite specification
vegaTooltip.vegaLite(result.view, url);
});
}
parse("/chart/anomaly/" + {{ graph }}, "pred");
</script>

我通过将json文件保存在本地并从另一个烧瓶路由检索该本地文件来解决这个问题。

最新更新