散景不会渲染

Bokeh Wont Render

我编写了一个非常简单的 Flask 应用程序来测试 Bokeh,但是我的 Bokeh 折线图无法呈现。它显示的是:

我的html是:

<html>
        <head>
            <meta charset="UTF-8">
    <link href="http://cdn.bokeh.org/bokeh/release/bokeh-2.0.0.min.css" rel="stylesheet" type="text/css">
    <script src="http://cdn.bokeh.org/bokeh/release/bokeh-2.0.0.min.js"></script>
        </head>
        <body>
            {{graph | safe}}
        </body>
    </html>

我的 flask 函数是:

app.route('/result')
def result():

    x = [1, 3, 5, 7]
    y = [2, 4, 6, 8]

    p = figure()

    p.circle(x, y, size=10, color='red', legend='circle')
    p.line(x, y, color='blue', legend='line')
    p.triangle(y, x, color='gold', size=10, legend='triangle')

    return render_template("result.html", graph=p)

目前pip安装的bokeh版本为2.0.0

您不能只将裸 Bokeh 对象传递给 Jinja 模板。有各种用于以不同方式嵌入内容的 Bokeh API。您将需要使用其中之一:

https://docs.bokeh.org/en/2.0.0/docs/user_guide/embed.html

对于像这样的独立内容,您需要 json_itemscomponentsautoload_static