As far as I can tell, this flavor of the "duplicate dcc.Location callback" issue (#883) hasn't been documented yet. When I run a multipage app, reloading the page fires the callback twice with the samehref / pathname / search payload. This is distinct from the other issue of having the callback return None and then returning the proper value(s).
importdash_core_componentsasdccimportdash_html_componentsashtmlfromdash.dependenciesimportInput, Output, Stateimportdash_bootstrap_componentsasdbcimportdashimporturllibnavbar=dbc.NavbarSimple(
brand='Frac Planning App',
brand_href='/',
sticky='top',
)
body=dbc.Container(
dbc.Row(
dbc.Col(id='page-content')
)
)
app.layout=html.Div([
dcc.Location(id='url', refresh=False),
navbar,
body
])
@app.callback(Output('page-content', 'children'), [Input('url', 'href')], [State('url', 'pathname'), State('url', 'search')])defdisplay_page(href, pathname, search):
print('HREF:', href)
print('PATHAME:', pathname)
print('SEARCH:', search)
url=urllib.parse.urlparse(href)
# print('RAW pathname:', url)print('TRIGGER(S):', [i['prop_id'] foriindash.callback_context.triggered])
ifurl.path=='/':
returnform.layoutelifurl.path=='/result':
query=dict(urllib.parse.parse_qsl(url.query))
returnresult.plot(**query)
else:
raisedash.exceptions.PreventUpdateHere is the output. It doesn't always print in the same order:
HREF: http://houmedge201:5004/
PATHAME: /
HREF: http://houmedge201:5004/
SEARCH: PATHAME: /
TRIGGER(S): ['url.href']
SEARCH: TRIGGER(S): ['url.href']
Running on Linux. Versions used:
dash 1.7.0
dash-core-components 1.6.0
dash-html-components 1.0.2
dash-renderer 1.2.2
I've tried the fix mentioned in #883 (comment) to no avail. Solving this is mission critical for my app because the duplicate callback crashes a subsequent database query.
Changing href via a html.Link makes the callback fire only once. However, users need to be able to share app URLs with query params, which right now is broken due to this bug.
As far as I can tell, this flavor of the "duplicate dcc.Location callback" issue (#883) hasn't been documented yet. When I run a multipage app, reloading the page fires the callback twice with the same
href/pathname/searchpayload. This is distinct from the other issue of having the callback returnNoneand then returning the proper value(s).Here is the output. It doesn't always print in the same order:
Running on Linux. Versions used:
I've tried the fix mentioned in #883 (comment) to no avail. Solving this is mission critical for my app because the duplicate callback crashes a subsequent database query.
Changing
hrefvia ahtml.Linkmakes the callback fire only once. However, users need to be able to share app URLs with query params, which right now is broken due to this bug.