我对Bokeh和烧瓶都是新手。我浏览了相关的问题、教程,并查看了Bokeh文档,但不知道我做错了什么。
话虽如此,我想创建一个简单的web应用程序,在这个应用程序中,我将各种数据报告和情节“组合在一起”。
根据我所读到的,我想出了以下几点:
app.py:
... # imports
app = Flask(__name__, static_url_path='/static')
@app.route("/")
def index():
return render_template("index.html")
@app.route("/bokeh_test")
def bokeh_test():
script, div = components(sample_plot())
return render_template("bokeh_test.html", script=script, div=div)
def sample_plot():
"""
A random plot just for testing purposes.
:return: plot
"""
PLOT_OPTIONS = dict(plot_width=600, plot_height=400)
SCATTER_OPTIONS = dict(size=12, alpha=0.5)
data = lambda: [random.choice([i for i in range(100)]) for r in range(10)]
plot = figure(sizing_mode='scale_both', tools='pan', **PLOT_OPTIONS)
plot.scatter(data(), data(), color="red", **SCATTER_OPTIONS)
# show(plot)
return plot
bokeh_test.html:
<!DOCTYPE html>
<html lang="en">
<head>
<!-- Bokeh includes-->
<script type="text/javascript" src="http://cdn.bokeh.org/bokeh/release/bokeh-0.12.13.min.js"></script>
<link rel="stylesheet" href="http://cdn.bokeh.org/bokeh/release/bokeh-0.12.13.min.css" type="text/css" />
{{ script|safe }}
</head>
<body>
<div>
<h1>Bokeh sample</h1>
<div class='bokeh'>
{{ div|safe }}
</div>
</div>
</body>
</html>
想象一下,在我的index.html文件中,我有一个带有指向bokeh_test.html的链接的边栏。当我点击它时,我看到的只是标题"bokeh样例“,但没有任何情节。
如果我取消了对“显示(图)”的注释,就会打开一个新的选项卡,并正确地显示该图,因此问题似乎不是在情节本身,而是在我试图将其嵌入到bokeh_test中的方式上。
我对这一切并不熟悉,所以也许我在做一些愚蠢的事情,但我还没有弄清楚,我希望能得到一些帮助。
PS。不确定是否相关,但为此,我从Anaconda 2创建了一个python 3.6环境,并将此环境用作项目解释器。
发布于 2018-11-26 06:34:01
您正在从模板中的CDN加载BokehJS版本0.12.13。那里的版本需要与系统中安装的Bokeh版本完全匹配。
https://stackoverflow.com/questions/53474808
复制相似问题