python - 如何修复 Dash App 异常 - 输出值的数量无效,预期为 2,得到 1?
问题描述
我使用plotly dash app
框架并具有具有多个输出值的回调函数。
当我尝试部署应用程序时,它会引发 Dash 异常。Invalid number of output values...
我试图使用[]
和删除它们。但是,仍然注意到异常。
这是应用程序布局的样子:
app.layout = html.Div([
# header
html.Div([
dcc.Link(
href=app.get_relative_path('/home'),
children='Home'
),
dcc.Link(
href=app.get_relative_path('/history'),
children='History'
),
# For pdf downloads
dash_extensions.Download(id="download"),
dcc.Location(id="url"),
# Page content
html.Div(id="page-content"),
# Tab content
html.Div(id="tab_content"),
])
打回来
# Update page content
@app.callback([
Output('page-content', 'children'),
Output('download', 'data')
],
[Input('url', 'pagename')]
)
def display_content(page_name):
# Pages and Links
if not page_name:
return [dash.no_update, dash.no_update]
if page_name == 'history:
return [history.layout(), dash.no_update]
else:
return ['404 Error', dash.no_update]
从日志中追溯:
Traceback (most recent call last):
File "/app/.heroku/python/lib/python3.6/site-packages/flask/app.py", line 1950, in full_dispatch_request
....
_validate.validate_multi_return(output_spec, output_value, callback_id)
File "/app/.heroku/python/lib/python3.6/site-packages/dash/_validate.py", line 126, in validate_multi_return
callback_id, len(outputs_list), len(output_value)
172.17.0.19 - - [03/Sep/2020:06:03:32 +0000] "POST /dash-app/_dash-update-component HTTP/1.1" 500 69 "https://example.com/dash-app" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.83 Safari/537.36"
dash.exceptions.InvalidCallbackReturnValue: Invalid number of output values for ..page-content.children...download.data...
Expected the output type to be a list or tuple, but got 1
解决方案
该方法display_content
希望您返回两个值。相反,您返回一个值,一个列表。
所以改为写:
return history.layout(), dash.no_update
和
return '404 Error', dash.no_update
推荐阅读
- python - sys.stdout 显示我没有写的东西
- javascript - 在同一行上有多个等号是什么意思?
- java - 在游戏中实现关卡完成计数器
- javalite - ActiveWeb:子包中的自定义控制器不起作用
- sql - 根据当前值获取下一个更高的值
- amazon-web-services - 将 AWS SSM PutParameter 限制为特定层次结构中的参数
- gwt - GWT 的 SplitLayoutPanel:获取调整大小通知
- cakephp - 如何在 cakephp 3.x 中编写这些代码行
- php - 跟踪车辆和司机的历史
- selenium - org.openqa.selenium.remote.ProtocolHandshake createSession 信息:尝试使用 Selenium Grid 进行双语会话