dash
dash copied to clipboard
dcc location callback nav
Improve page navigation when dcc.Location
is updated in a callback.
Currently when dcc.Location is updated in a callback, the browser url is updated, but it does not navigate to the new page unless the browser is refreshed. This PR makes it unnecessary to refresh the browser -- giving the same fast navigation as when user clicks on a dcc.Link
.
See a demo app in the usage-dcc-location-callback-nav
folder.
As requested on the Dash Community Forum
Limitations
The following issues occur when there are multiple dcc.Location
components in a multi-page app. These are all existing issues and are not new based on changes in this PR. It they aren't fixed as part of the PR, then it would be helpful to document the workarounds.
-
There are potential conflicts when callbacks update multiple
dcc.Location
location causing the browser to crash. -
When using in a multi-page app with multiple
dcc.Location
components, they must all be on the same page - typically theapp.py
file. (Or theindex.py
if using the multi-page structure whereapp
is defined in it's own file) -
When navigating to a page with the callback to update the
dcc.Location
the callback is fired even whenprevent_initial_call=True
This has been reported in issue 1346 and issue 1985 -
Browser forward/back doesn't work when there are multiple
dcc.Location
components
Contributor Checklist
- [ ] I have broken down my PR scope into the following TODO tasks
- [ ] Investigate whether it's necessary to add the "callback-nav" option. Should this just be the default, or are there other use-cases for
refresh=True
andrefresh=False
- [ ] Investigate why the browser forward/back does not work when using more than one
dcc.Location
- [ ] Investigate whether it's necessary to add the "callback-nav" option. Should this just be the default, or are there other use-cases for
- [x] I have run the tests locally and they passed. (refer to testing section in contributing)
- [x] I have added tests, or extended existing tests, to cover any new features or bugs fixed in this PR
optionals
- [ ] I have added entry in the
CHANGELOG.md
- [ ] If this PR needs a follow-up in dash docs, community thread, I have mentioned the relevant URLS as follows
- [ ] this GitHub #PR number updates the dash docs
- [ ] here is the show and tell thread in Plotly Dash community