I have a multi page app
dash - 2.17.1
dcc - 2.14.1
html - 2.0.18
dash_table - 5.2.11
Windows OS
Browser - Edge
I have a multi-page Dash app with a home page and a detail page (using the path template /detail/:id. On the home page, there’s a dropdown for selecting IDs. When an ID is selected, it should redirect to /detail/:selected id using dcc.Location. This is done through a callback on the homepage.
data is a df with name and id columns
> layout = dbc.Container([
> dbc.Row([
> dbc.Col([
> html.H6("Analysis", className="app-subtitle text-center"),
> dcc.Dropdown(
> id="dropdown-results",
> options=[],
> placeholder="Search by Name or ID",
> multi=False,
> value=None
> ),
> dcc.Location(id='url', refresh=True),
> ], width=8),
> ], justify='center', align='center'),
> ], fluid=True)
>
> @callback(
> Output("dropdown-results", "options"),
> Input("dropdown-results", "search_value")
> )
> def update_dropdown(search_value):
> if not search_value:
> return []
> filtered_df = data[
> (data['name'].str.contains(search_value, case=False, na=False)) |
> (data[id'].astype(str).str.contains(search_value, case=False, na=False))
> ]
>
> if filtered_df.empty:
> return []
>
> # Format the dropdown options
> options = [
> {'label': f"{row['name']} - {row['name']} (ID: {row['id']})", 'value': row['id']}
> for index, row in data.iterrows()
> ]
>
> return options
>
> @callback(Output('url', 'pathname'),
> [Input('dropdown-results', 'value')])
> def display_page(selected_value):
> if selected_value:
> str_id= str(selected_value)
> print(str_id)
> return f"/detail/{str_id}"
The issue is that sometimes the URL changes as expected, but other times it doesn’t, showing inconsistency. Although I can see that str_id is printed always, the URL isn’t always updated or redirected to the new page.
Do you have any pointers on how to debug this inconsistency?
Thanks!