【问题标题】:Troubleshooting error returned by dash table破折号表返回的故障排除错误
【发布时间】:2019-01-31 16:40:29
【问题描述】:

我正在尝试在 Dash 中显示一个表格。我导入 dash_table 并收到错误消息: KeyError:'地图'

python页面很简单:

import dash
import dash_table
import pandas as pd
import dash_html_components as html

app = dash.Dash(__name__)

app.layout = html.Div([
        html.H3('A Table')
])

if __name__ == '__main__':
    app.run_server(debug=True)

页面一加载,错误就会出现。注释掉“import dash_table”会使错误消失。如您所见,我什至没有创建表。 我正在运行 python 3.6.3。我没有使用虚拟环境。 其他人是否收到此错误消息?有没有 dash_table 的替代品?

【问题讨论】:

    标签: python html plotly-dash


    【解决方案1】:

    您好像忘记指定dash_table.DataTable(),而只将名称“A Table”指定为html.H3

    代码:

    import dash
    import dash_table
    import dash_html_components as html
    import pandas as pd
    
    app = dash.Dash(__name__)
    
    df = pd.DataFrame({'Item': [1, 1, 1, 2, 2, 3],
                       'Status': ["First", "Second", "Third",
                                  "First", "Second", "First"],
                       'Value': [2000, 3490, 542, 641, 564, 10]})
    
    app.layout = html.Div([
            html.H3('A Table', style={'textAlign': 'center'}),
            dash_table.DataTable(
                id='table',
                columns=[{"name": i, "id": i} for i in df.columns],
                data=df.to_dict("rows"),
                )
            ]
    )
    
    if __name__ == '__main__':
        app.run_server(debug=True)
    

    输出:

    您可以了解有关如何正确使用 dash-table 的更多信息 - 只需查看文档 here。希望对你有帮助

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多