Hi,
I met an dupilicate issue when change main page element from sub page:
Here is a small example: (sorry I didn’t find a way to do code formatting here)
app.py:
import dash
from dash import Dash, html, dcc
app = Dash(__name__, use_pages=True)
app.layout = html.Div([
html.H1('Multi-page app with Dash Pages'),
html.Div(id="page_name"),
dcc.Location(id='url', refresh=True),
html.Div([
html.Div(
dcc.Link(f"{page['name']} - {page['path']}", href=page["relative_path"])
) for page in dash.page_registry.values()
]),
dash.page_container
])
if __name__ == '__main__':
app.run(debug=True)
archive.py:
import dash
from dash import html, callback, Input, Output
dash.register_page(__name__)
layout = html.Div([
html.H1('This is our Archive page'),
html.Div('This is our Archive page content.'),
])
@callback(
Output("page_name", "children", allow_duplicate=True),
Input("url", "pathname"),
prevent_initial_call=True,
)
def update_page_name(url):
return url
home.py:
import dash
from dash import html, callback, Input, Output
dash.register_page(__name__, path='/')
layout = html.Div([
html.H1('This is our Home page'),
html.Div('This is our Home page content.'),
])
@callback(
Output("page_name", "children", allow_duplicate=True),
Input("url", "pathname"),
prevent_initial_call=True,
)
def update_page_name(url):
return url
In archive.py and home.py there is a callback to change an element in app.layout. But it always cause issue:
Duplicate callback outputs
In the callback for output(s):
page_name.children@b80108fca58ba4aeaa5e8c587a7e4ff4
Output 0 (page_name.children@b80108fca58ba4aeaa5e8c587a7e4ff4) is already in use.
To resolve this, setallow_duplicate=True
on
duplicate outputs, or combine the outputs into
one callback function, distinguishing the trigger
by usingdash.callback_context
if necessary.
Can anyone peovide any suggest to fix that?
Thanks in advance.