我正试图在Dash中显示一个表。我导入dash_table并收到错误:KeyError:'map'
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的替代品?
看起来你忘了指定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)
您可以了解有关如何正确使用破折号表的更多信息 - 只需查看文档here即可。希望它能帮到你