在输出回调中: 页面内容.children 输出 0 (page-content.children) 已在使用中。 任何给定的输出只能有一个设置它的回调。 要解决这种情况,请尝试将它们组合成 一个回调函数,区分触发 如有必要,可使用
dash.callback_context
。
我在运行 Dash 应用程序时遇到上述错误,任何人都可以帮我解决这个问题。
这是我的布局部分
html.Div([
dbc.Row(
[
dbc.Col(dbc.NavbarBrand(dcc.Link(
html.Button(children='HOME',
style={
'marginLeft': '100px',
'marginRight': 'auto',
'display': 'inline-block',
'align': 'center', 'color': 'white'}, ),
href='/', refresh=True))),
dbc.Col(dbc.NavbarBrand(dcc.Link(
html.Button(children='OVERVIEW',
style={'margin-left': '100px',
'margin-right': 'auto', 'color': 'white', 'align': 'center'
}),
href='/apps/overview', refresh=True))),
dbc.Col(dbc.NavbarBrand(dcc.Link(
html.Button(children='GRAPH',
style={'marginLeft': '100px',
'marginRight': 'auto', 'color': 'white', 'align': 'center'
}),
href='/apps/graph_page', refresh=True))),
dbc.Col(dbc.NavbarBrand(dcc.Link(
html.Button(children='CONSOLE',
style={'marginLeft': '100px',
'marginRight': 'auto', 'color': 'white', 'align': 'center'
}),
href='/log_stream', refresh=True))),
],
style={
'height': 'auto',
'width': 'auto',
'background-color': '#101820',
'align-items': 'center',
'diplay': 'flex',
},
align="center",
no_gutters=True,
),
dcc.Location(id='url', refresh=False),
html.Div(id='page-content', children=[])
]),
html.Div([
dcc.Dropdown(
id='demo-dropdown',
options=[
{'label': 'Dummy', 'value': 0},
{'label': 'CAN', 'value': 1},
],
placeholder="Select a Mode",
searchable=False
),
html.Div(id='dd-output-container')
])
])
这些是我的回调
@app.callback(
Output('dd-output-container', 'children'),
Input('demo-dropdown', 'value'))
def update_output(value):
return 'You have selected "{}"'.format(value)
@app.callback(Output(component_id='page-content', component_property='children'),
(Input(component_id='url', component_property='pathname')))
def display_page(pathname):
if pathname == '/apps/graph_page':
return graph_page.layout
elif pathname == '/apps/overview':
return overview.layout
提前谢谢您。
我在另一个脚本中有一个重复的回调,我一开始没有注意到。
如果您有多页面设置,即使跨页面,组件 ID 也需要是唯一的。