python-3.x - 例外:布局必须是破折号组件或返回破折号组件的函数
问题描述
我正在尝试这段简单的代码,它正在引发标题中提到的异常。
import dash
import dash_core_components as dcc
import dash_html_components as html
import plotly.graph_objs as go
import pandas as pd
df=pd.read_excel("https://github.com/chris1610/pbpython/
blob/master/data/salesfunnel.xlsx?raw=True")
pv = pd.pivot_table(df, index=['Name'], columns=["Status"], values=
['Quantity'], aggfunc=sum, fill_value=0)
trace1 = go.Bar(x=pv.index, y=pv[('Quantity', 'declined')], name='Declined')
trace2 = go.Bar(x=pv.index, y=pv[('Quantity', 'pending')], name='Pending')
trace3 = go.Bar(x=pv.index, y=pv[('Quantity', 'presented')], name='Presented')
trace4 = go.Bar(x=pv.index, y=pv[('Quantity', 'won')], name='Won')
app = dash.Dash()
app.layout = html.Div(children=[
html.H1(children='Sales Funnel Report'),
html.Div(children='''National Sales Funnel Report.'''),
dcc.Graph(
id='example-graph',
figure={
'data': [trace1, trace2, trace3, trace4],
'layout':
go.Layout(title='Order Status by Customer', barmode='stack')
})
])
所以,它指向程序的最后一行,即 go.Layout 并提到了这个错误。我已经尝试了很多东西,但我找不到这个错误的原因。如果有人能解决这个问题,那将是很大的帮助。提前致谢, 问候
解决方案
我无法重现此异常。Id 确实必须更改给定代码中的两件事。
1)行中的杂散换read_excel
行(可能是代码复制的神器)
2)添加以下内容以实际运行应用程序:
if __name__ == '__main__':
app.run_server(debug=True)
这些可能非常微不足道,您的问题可能完全不同,但是在这两个更改之后,应用程序对我来说运行顺利。
推荐阅读
- java - Java:使用 HTTPUrlConnection 下载的 ZIP 文件已损坏
- php - 如何使用不是我的父主题的主题模板
- gcc - 在交叉编译 gcc binutils 和 glibc 之类的东西时如何使用 --with-cpu 和 --with-arch
- node.js - Node 只下载某些 url 的部分图片
- awk - 使用 awk 更改文件中第一列的值
- python - Dask 线程如何与 OpenBLAS/MKL/... 交互?
- sql - 字符串以字符结尾
- wmi - 仅使用 wmi 类获取磁盘空间大小,仅此而已
- c# - 任何人都知道如何从代码中间调用功能文件 - Specflow & c#
- vhdl - IS_X 函数综合