首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >显示Bokeh工具栏时出现问题

显示Bokeh工具栏时出现问题
EN

Stack Overflow用户
提问于 2018-06-08 05:23:26
回答 1查看 1.1K关注 0票数 0

一般来说,我对Bokeh和flask python是个新手,但我已经设法创建了一个图形,然后通过Flask在我的浏览器上输出它。唯一的问题是我没有在我的图表旁边看到"Bokeh工具栏“。

我的代码如下所示

代码语言:javascript
复制
from flask import Flask, render_template, request
import pandas as pd
import csv
from bokeh.plotting import figure
from bokeh.io import show
from bokeh.embed import components
from bokeh.models import Range1d
from bokeh.resources import CDN

app = Flask(__name__)


# Create the main plot
    def create_figure():
    xvals = []
    yvals = []
    with open('test.csv') as csvfile:
        readCSV = csv.reader(csvfile, delimiter=',')

        for row in readCSV:
            xvalue = row[0]
            yvalue = row[1]
            xvals.append(xvalue)
            yvals.append(yvalue)

    p = figure(plot_width=400, plot_height=400, x_range=(0, 20))
    p.y_range = Range1d(0, 15)
    p.circle(xvals, yvals, size=10)
    return p
# Index page
@app.route('/')
def index():
    plot = create_figure()
    script, div = components(plot)
    cdn_js = CDN.js_files[0]
    cdn_css = CDN.css_files[0]
    return render_template("index.html", script=script, div=div, 
    cdn_js=cdn_js, 
    cdn_css=cdn_css)
    # With debug=True, Flask server will auto-reload
    # when there are code changes
    if __name__ == '__main__':
        app.run(port=5000, debug=True)

我的index.html代码看起来像这样:

代码语言:javascript
复制
<html>
<head>
<link href={{ cdn_css|safe }} type="text/css" />
<script type="text/javascript" src={{ cdn_js|safe }}></script>
</head>
<body>
<H1>First</H1>

{{ script|safe }}
{{ div|safe }}

</body>
</html>

我是不是遗漏了什么?当我将图形输出到output_file时,我得到了工具栏。任何帮助都将不胜感激。

EN

回答 1

Stack Overflow用户

发布于 2018-06-22 01:58:08

我也有同样的问题。我不能解释其中的原因,但是这个例子可以工作:realpython github

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50750359

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档