Hi,
I am currently trying to build a multipage app where choices made by the user (e.g. in dropdown menus) are saved in dcc. Store. When returnign to a page the choices made last time are supposed to be restored. I am running in the following error:
A nonexistent object was used in an `Input` of a Dash callback. The id of this object is `p1-dropdown` and the property is `value`. The string ids in the current layout are: [global-store, _pages_location, _pages_content, _pages_store, _pages_dummy]
app.py
from dash import Dash, html, dcc
import dash
app = Dash(__name__, use_pages=True)
app.layout = html.Div([
html.H1('Multi-page app with Dash Pages'),
dcc.Store(id='global-store', storage_type='session'),
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_server(debug=True)
page_1.py
import dash
from dash import html, dcc, callback, Input, Output
import dash_bootstrap_components as dbc
df = ['abc', 'def', 'ghi', 'xyz']
dash.register_page(__name__)
layout = html.Div(children=[
dcc.Dropdown(
id = 'p1-dropdown',
options = [{'label':x, 'value':x} for x in df]
)
])
@callback(Output('p1-dropdown', 'value'),
Output('global-store', 'data'),
Input('p1-dropdown', 'value'),
Input('global-store', 'data')
)
def setup_dropdown(value_chosen, value_stored):
if value_chosen is None:
return value_stored, value_stored
else:
return value_chosen, value_chosen
The callback has two purposes:
(i) if there is a value stored in dcc.Store it is used as âvalueâ for the dropdown
(ii) if the user chooses a new value in the dropdown it shall be stored to dcc.Store
From reading other posts I think the problem is that the callback looks for the âp1-dropdownâ and does not find it, as it is created later on. What can I do about this?