![](/img/trans.png)
[英]How to fix Dash App Exception - Invalid number of output values Expected
[英]How to fix Dash App Exception - Invalid number of output values Expected 2, got 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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.