简体   繁体   English

如何修复 Dash 应用程序异常 - 输出值的数量无效,预期为 2,得到 1?

[英]How to fix Dash App Exception - Invalid number of output values Expected 2, got 1?

I using plotly dash app framework and have callback functions with multiple output values.我使用plotly dash app框架并具有具有多个输出值的回调函数。

When I attempt to deploy the app, it throws an Dash exception.当我尝试部署该应用程序时,它会引发 Dash 异常。 Invalid number of output values... I have tried to use [] and remove them. Invalid number of output values...我尝试使用[]并删除它们。 However, still noticing the exception.但是,仍然注意到异常。

Here's what App Layout looks like:这是应用程序布局的样子:


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"),

      ])

Callback打回来


# 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 from the logs:从日志回溯:


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

the method display_content expects you to return two values.方法display_content期望您返回两个值。 Instead you return a single value, a list.相反,您返回一个值,一个列表。

So instead write:所以改为写:

return history.layout(), dash.no_update

and

return '404 Error', dash.no_update

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何修复 Dash 应用程序异常 - 预期的输出值数量无效 - How to fix Dash App Exception - Invalid number of output values Expected 破折号应用程序错误:没有足够的值来解压缩(预期2,获得1) - Dash app Error: not enough values to unpack (expected 2, got 1) Plotly 错误 - ..my-graph.figure…download.href…的 output 值的数量无效…预期 2,得到 3 - Plotly error - Invalid number of output values for ..my-graph.figure…download.href… Expected 2, got 3 如何解决“没有足够的值来解压(预期2,得到1)”? - How to fix “not enough values to unpack (expected 2, got 1)”? 如何修复烧瓶中的“预期令牌',','无效'”错误 - How to fix “expected token ',', got 'invalid'” eroor in flask 如何修复查找和字段 'id' 需要一个数字但出现 '' 错误 - How to fix find and Field 'id' expected a number but got '' error 如何修复 ValueError:没有足够的值来解包(预期为 2,得到 1) - How to fix ValueError: not enough values to unpack (expected 2, got 1) 如何修复“ValueError:没有足够的值来解包(预期 2,得到 1)” - How to fix “ValueError: not enough values to unpack (expected 2, got 1)” 如何修复“ValueError:没有足够的值来解压(预期为 2,得到 1)” - How to fix "ValueError: not enough values to unpack (expected 2, got 1)" 如何修复:ValueError: no enough values to unpack (expected 2, got 1) - How to fix:ValueError: not enough values to unpack (expected 2, got 1)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM