Python 烧瓶中未显示Bokeh数据表

Python 烧瓶中未显示Bokeh数据表,python,flask,bokeh,Python,Flask,Bokeh,我正在开发一个Flask web应用程序,以在DataTable中显示数据,并由Bokeh构建交互式报告。我下面的代码显示bokeh DataTable不工作 from flask import Flask, render_template, request import pandas as pd from bokeh.embed import components from bokeh.models.widgets import DataTable, DateFormatter, TableC

我正在开发一个Flask web应用程序,以在DataTable中显示数据,并由Bokeh构建交互式报告。我下面的代码显示bokeh DataTable不工作

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>

Iris数据表版本5
{{script | safe}}
{{div | safe}}
我的web应用程序只显示标题“Iris数据表版本5”,但不显示Bokeh数据表,也没有错误消息


我想不出哪里错了,谢谢你的帮助。

你没有包括表的JS/CSS文件。它们相对较大,所以它们被分割成自己的文件,这样不使用表的人就不必支付加载资源的费用。下面是一个工作模板。注:我还更新了CDN URL,指向
CDN.bokeh.org
。旧位置将无限期地工作,但任何有能力的人都应该使用新位置

<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">

<link
    href="http://cdn.bokeh.org/bokeh/release/bokeh-tables-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>
<script src="http://cdn.bokeh.org/bokeh/release/bokeh-tables-0.12.16.min.js"></script>

</head>
<body>
<H1>Iris Data Table version 5</H1>

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

</body>
</html>

Iris数据表版本5
{{script | safe}}
{{div | safe}}

您没有包括表的JS/CSS文件。它们相对较大,所以它们被分割成自己的文件,这样不使用表的人就不必支付加载资源的费用。下面是一个工作模板。注:我还更新了CDN URL,指向
CDN.bokeh.org
。旧位置将无限期地工作,但任何有能力的人都应该使用新位置

<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">

<link
    href="http://cdn.bokeh.org/bokeh/release/bokeh-tables-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>
<script src="http://cdn.bokeh.org/bokeh/release/bokeh-tables-0.12.16.min.js"></script>

</head>
<body>
<H1>Iris Data Table version 5</H1>

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

</body>
</html>

Iris数据表版本5
{{script | safe}}
{{div | safe}}

0.12.16实际上是您安装的Bokeh版本吗?是的,我在浏览器JS控制台或“网络调试”选项卡中检查了Bokeh版本。错误/消息?您也可以尝试将表作为某些布局(例如
)中的唯一项。我知道有一些版本的裸小部件存在问题(我原以为是0.12.16之前的版本,但我的记忆可能不好)@bigreddot谢谢,浏览器没有错误,sublime text py控制台也没有错误。只是没有显示表格:(0.12.16实际上是您安装的Bokeh版本吗?是的,我在浏览器JS控制台或网络调试选项卡中检查了Bokeh版本。错误/消息?您也可以尝试将表作为某些布局中的唯一项(例如
)我知道有一些版本的裸小部件存在问题(我原以为是0.12.16之前的版本,但我的记忆可能不好)@bigreddot谢谢,浏览器没有错误,sublime text py控制台也没有错误。只是没有显示表格:(太好了!!!!非常感谢你,它正在工作!!!很抱歉回答的帖子不正确,有时就是想不出该怎么办。我想知道你是否可以帮我买另一张票“如何删除bokeh表中的NaN”--非常感谢。太好了!!!!非常感谢,它正在工作!!!很抱歉,作为回答的帖子不正确,有时就是不知道该怎么办。我想知道你是否可以帮我买另一张票“如何在bokeh表中删除NaN”-非常感谢。