我有用于各种仪表板(REST 调用、CSV、Excel 等)的 dash 多页应用程序。问题是索引页面包含应用程序加载的路径,这些应用程序会幼稚地调用页面模块。
代码是调用模块的基础..
print(dcc.__version__) # 0.6.0 or above is required
app.layout = html.Div([
dcc.Location(id='url',refresh=True),html.Div(id='page-content')
])
@app.callback(Output('page-content','children'),Input('url','pathname'))
def display_page(pathname):
global count
count+=1
print("running index.py {} for {}".format(str(count),pathname))
time.sleep(2.0)
if pathname == '/apps/app1':
return app1.layout
elif pathname == '/apps/app2':
return app2.layout
elif pathname == '/apps/dashboard':
return dashboard.layout
elif pathname == '/apps/alm_report':
return alm_report.layout
else:
return '404'
if __name__ == '__main__':
app.run_server(debug=True)
所以我每 2 秒得到一次“Running Index.py count”。如果我将睡眠时间设置为 20 秒(只是为了验证页面本身没有错误),页面工作正常。页面具有基于所选输入的 DCC html 布局和图形
该应用程序在 Windows 7 Python 3.7 上运行良好。我最近安装了 Windows 10 和 Python 3.9 (venv) + Dcc 1.14.1。我开始收到此错误的地方..
任何指点都非常有用。