【发布时间】:2020-03-02 10:05:58
【问题描述】:
我正在开发一个 Flask Web 应用程序来在 DataTable 中显示数据,并通过 Bokeh 构建交互式报告。我下面的代码显示散景数据表不起作用。
from flask import Flask, render_template, request
import pandas as pd
from bokeh.embed import components
from bokeh.models.widgets import DataTable, DateFormatter, TableColumn
from bokeh.models.sources import ColumnDataSource
app = Flask(__name__)
# Load the Iris Data Set
iris_df = pd.read_csv("/data/iris.data", names=["Sepal Length", "Sepal Width", "Petal Length", "Petal Width", "Species"])
@app.route('/ShowIrisDataTable/')
def index():
cols = [
TableColumn(field='Sepal Length', title='Sepal Length'),
TableColumn(field='Sepal Width', title='Sepal Width'),
TableColumn(field='Petal Length', title='Petal Length'),
TableColumn(field='Petal Width', title='Petal Width'),
TableColumn(field='Species', title='Species')
]
data_table = DataTable(columns=cols, source=ColumnDataSource(iris_df), fit_columns=True)
script, div = components(data_table)
return render_template("iris_index5.html", script=script, div=div)
if __name__ == '__main__':
app.run(port=5000, debug=True)
我的html文件如下:
<html>
<head>
<link
href="http://cdn.bokeh.org/bokeh/release/bokeh-0.12.16.min.css"
rel="stylesheet" type="text/css">
<link
href="http://cdn.bokeh.org/bokeh/release/bokeh-widgets-0.12.16.min.css"
rel="stylesheet" type="text/css">
<script src="http://cdn.bokeh.org/bokeh/release/bokeh-0.12.16.min.js"></script>
<script src="http://cdn.bokeh.org/bokeh/release/bokeh-widgets-0.12.16.min.js"></script>
</head>
<body>
<H1>Iris Data Table version 5</H1>
{{ script|safe }}
{{ div|safe }}
</body>
</html>
我的网络应用程序只显示标题“虹膜数据表版本 5”,但不显示散景数据表,也没有错误消息。
我不知道哪里错了,感谢您的帮助。
【问题讨论】:
-
0.12.16 真的是你安装的 Bokeh 版本吗?
-
是的,我检查了散景版本。
-
浏览器 JS 控制台或网络调试选项卡中的错误/消息?
-
您也可以尝试将表格作为某些布局中的唯一项目(例如
column)内存可能已关闭) -
@bigreddot 谢谢,浏览器没有错误,sublime text py 控制台也没有错误。它只是没有显示表格:(