-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG] No callback to dcc.Location when two or more dcc.Location are placed in layout #1312
Comments
@papalagichen Did you find a solution to this? I'm experiencing the same issue |
Here is a minimal example. Note that this is only reproducible when not using Pages
from dash import Dash, dcc, html, Input, Output, callback
page1 = html.Div("PAGE 1 CONTENT")
page2 = html.Div("Page 2 content")
app = Dash(__name__, suppress_callback_exceptions=True)
server = app.server
app.layout = html.Div([
dcc.Location(id='url', refresh=False),
#dcc.Location(id='url2', refresh=False),
dcc.Link('Go to Page 2', href='/page2'),
html.Br(),
dcc.Link('Go to Page 1', href='/page1'),
html.Div(id='page-content')
])
@callback(Output('page-content', 'children'),
Input('url', 'pathname'))
def display_page(pathname):
if pathname == '/page1':
return page1
elif pathname == '/page2':
return page2
elif pathname == '/':
return page1
else:
return '404'
if __name__ == '__main__':
app.run_server(debug=True) Here is a similar app with Pages - Can't reproduce the error: import dash
from dash import Dash, html, dcc
app = Dash(__name__, use_pages=True, pages_folder="")
dash.register_page("stocks", layout=html.Div("stocks page"))
dash.register_page("home", path="/", layout=html.Div("home page"))
app.layout = html.Div(
[
dcc.Location(id="url", refresh=False),
dcc.Location(id="url2", refresh=False),
dcc.Link('Stocks', href='/stocks'),
html.Br(),
dcc.Link('Home', href='/'),
dash.page_container,
]
)
if __name__ == "__main__":
app.run(debug=True)
|
Multiple dcc.Location were replacing the others event handlers for 'popstate'. If any dcc.Location was unmounted, there was no event handler left fix plotly#1312
Multiple dcc.Location were replacing the others event handlers for 'popstate'. If any dcc.Location was unmounted, there was no event handler left fix plotly#1312
I encountered the same problem while using pages. The bug is triggered when one of the Having a import dash
from dash import Dash, html, dcc
app = Dash(__name__, use_pages=True, pages_folder="")
dash.register_page("stocks", layout=[
html.Div("stocks page"),
dcc.Location(id="url", refresh=False),
])
dash.register_page("home", path="/", layout=html.Div("home page"))
app.layout = html.Div(
[
dcc.Location(id="url2", refresh=False),
dcc.Link('Stocks', href='/stocks'),
html.Br(),
dcc.Link('Home', href='/'),
dash.page_container,
]
)
if __name__ == "__main__":
app.run(debug=True) I have made PR in #2555 that should fix the issue. |
Thank you so much for helping improve the quality of Dash!
We do our best to catch bugs during the release process, but we rely on your help to find the ones that slip through.
Describe your context
Please provide us your environment so we can easily reproduce the issue.
pip list | grep dash
belowif frontend related, tell us your Browser, Version and OS
Describe the bug
In a multi-page app, browser's back and forward buttons do not work when multiple dcc.Location components are placed in layout. No callback is triggered nor request is sent when browser's back or forward button is clicked. As a result, I see the URL is changed while the page is not rendered accordingly.
Two dcc.Location are placed in the layout like following code snippet.
Expected behavior
When URL is changed, the corresponding callback should be called and page should be rendered accordingly.
Screenshots
The text was updated successfully, but these errors were encountered: