【问题标题】:Javascript Bokeh Plot not rendering in browserJavascript Bokeh Plot 未在浏览器中呈现
【发布时间】:2020-05-09 09:37:03
【问题描述】:

我正在创建散景图,并传递 html 代码 script, div = components(plot)

return render_template('results.html',the_div=div,the_script=script)

脚本和 div 已被传递到浏览器,但显示的不是绘图,而是 html 代码。

{% extends "bootstrap/base.html" %}
{% import "bootstrap/wtf.html" as wtf %}

{% block html_attribs %} lang="en" charset="utf-8"{% endblock %}

{% block title %}  Results {% endblock %}
{% block metas %}
</mysite/static/favicon-96x96.png">
<link rel="stylesheet" href= "https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">

<script src="https://cdn.bokeh.org/bokeh/release/bokeh-2.0.2.min.js"
        crossorigin="anonymous"></script>
<script src="https://cdn.bokeh.org/bokeh/release/bokeh-widgets-2.0.2.min.js"
        crossorigin="anonymous"></script>
<script src="https://cdn.bokeh.org/bokeh/release/bokeh-tables-2.0.2.min.js"
        crossorigin="anonymous"></script>


{% endblock %}

{% block content %}

<div class="container">
        {{ the_script }}
        {{ the_div }}
</div>

有人能指出我哪里出错了吗? -我检查了我使用的散景版本是 2.0.2 我不熟悉 javascript,所以我假设它可能是一个简单的修复

来自浏览器控制台的视图:

【问题讨论】:

    标签: javascript html rendering bokeh


    【解决方案1】:

    默认情况下,所有模板参数都被转义以防止它们改变 DOM 结构。 由于您确实需要更改 DOM 结构,因此您只需将 |save 添加到每个变量:

    {{ the_script|safe }}
    {{ the_div|safe }}
    

    更多详情:https://jinja.palletsprojects.com/en/2.11.x/templates/#working-with-automatic-escaping

    【讨论】:

    • 感谢 Eugene,我已将 |save 添加到每个变量中,现在 html 代码未在视图中呈现,但我的绘图未呈现。我可以在源代码中看到代码仍然存在.. 是否有其他东西可以阻止绘图被渲染?
    • 您在 JavaScript 控制台中看到什么了吗?
    • Eugene 我刚刚从控制台添加了视图。我是新手,所以我还没有改变来研究这意味着什么。但我可以看到存在某种错误。
    • 我看到你的 BokehJS 版本是 2.0.2。但是你的 Bokeh Python 包的版本是什么?好像他们不一样。似乎您可能正在使用 DataRange1d.callback 属性 - 此属性已被弃用,后来被删除。
    • 非常感谢 Eugene 我将版本更新到 1.3.4,现在它正在显示。
    【解决方案2】:

    您的控制台屏幕截图显示了问题。您正在尝试从 CDN 加载使用 Python Bokeh 版本 1.3.4 和 BokehJS 版本 2.0.2 生成的 Bokeh JSON。这不受支持且不起作用(版本必须匹配)。

    【讨论】:

    • 太棒了!我将版本更新到 1.3.4,现在它可以工作了!非常感谢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-02-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-14
    相关资源
    最近更新 更多