我正在尝试这段简单的代码,并且正在引起标题中提到的异常。
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)
这些可能非常琐碎,您的问题可能完全不同,但是在这两项更改之后,该应用程序对我来说运行顺利。