简体   繁体   English

如何修复 Dash 应用程序异常 - 预期的输出值数量无效

[英]How to fix Dash App Exception - Invalid number of output values Expected

I using plotly dash app framework to build an multi-page app.我使用plotly dash app框架来构建一个多页应用程序。 I have callback functions with multiple output values, one callback is for tab_content and other one to update page_content.我有多个输出值的回调函数,一个回调用于 tab_content,另一个用于更新 page_content。

Upon deploying the app, it throws an exception when I click Home page and doesn't render the content in callback.在部署应用程序时,当我单击Home时它会引发异常并且不会在回调中呈现内容。 Desired behavior is upon clicking Home , the page content refreshes and renders tab content.所需的行为是在单击Home ,页面内容刷新并呈现选项卡内容。


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 tab content, if pagename == 'home' then return tab1 layout更新选项卡内容,如果 pagename == 'home' 然后返回 tab1 布局



@app.callback([
               Output('tab-content', 'children'),
               
              ],
              [ 
               Input('tab', 'value')
               Input('url', 'pagename'),
              ]
             )
def display_content(tab, pagename):

    # Pages and Links

    if tab == 'tab1' or pagename == 'home':
        return tab1.layout

    if tab == 'tab2':
        return tab2.layout()


# 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 or page_name == 'home':
        return [dash.no_update, dash.no_update]

    if page_name == 'history':
        return [history.layout(), dash.no_update]

    else:
        return ['404 Error', dash.no_update]

I have also tried removing the list and modifying the return statement with no luck:我也尝试删除列表并修改返回语句,但没有运气:

if not page_name:
   return dash.no_update, dash.no_update

if page_name == 'history':
   return history.layout(), dash.no_update

I see the following traceback in Logs.我在日志中看到以下回溯。


Traceback (most recent call last):
File "/app/.heroku/python/lib/python3.6/site-packages/flask/app.py", line 1950, in full_dispatch_request
rv = self.dispatch_request()
File "/app/.heroku/python/lib/python3.6/site-packages/flask/app.py", line 1936, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/app/.heroku/python/lib/python3.6/site-packages/dash/dash.py", line 1050, in dispatch
response.set_data(func(*args, outputs_list=outputs_list))
File "/app/.heroku/python/lib/python3.6/site-packages/dash/dash.py", line 995, in add_context
_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 None

You're missing a quotation to close your string.您缺少关闭字符串的引号。 That should fix it.那应该解决它。


    if page_name == 'history': # this closing one here
        return [history.layout(), dash.no_update]

    else:
        return ['404 Error', dash.no_update]

暂无
暂无

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

相关问题 如何修复 Dash 应用程序异常 - 输出值的数量无效,预期为 2,得到 1? - How to fix Dash App Exception - Invalid number of output values 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) - Dash app Error: not enough values to unpack (expected 2, got 1) 如何查看 Dash 应用中的活跃用户数? - How to check number of active users in Dash app? 如何修复我的 Plotly Dash 应用程序组织不正确 - How to Fix My Plotly Dash App Not Organizing Properly 如何通过 url 从 Flask 应用程序向 dash 应用程序发送一些值? 烧瓶和破折号应用程序独立运行 - How to send some values through url from a flask app to dash app ? flask and dash app are running independently 如何解决“没有足够的值来解压(预期2,得到1)”? - How to fix “not enough values to unpack (expected 2, got 1)”? 如何修复烧瓶中的“预期令牌',','无效'”错误 - How to fix “expected token ',', got 'invalid'” eroor in flask 无效的参数数量异常 - Invalid number of parameters exception 例外:当返回 2 个值时,kivy 中的 App.root 中的实例无效 - Exception: Invalid instance in App.root in kivy when returning 2 values
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM