I too am getting the annoying “A nonexistent object was used in an Input
of a Dash callback” error when using dcc.Store in a dash app using Pages. I have spent the last two days reading every post on the topic and trying every solution I could find with no success. supress_callback_exceptions = True doesn’t fix anything, changing the Input to a State doesn’t fix anything, moving the logic setting dcc.Store into its own callback doesn’t fix anything, I’ve tried moving dcc.Store in app.layout, I’ve tried layout functions vs variables, I’ve tried different storage settings, but nothing works.
I couldn’t even manage to replicate the issue in a MRE, probably because of how complicated my actual layout is
My first question: Does this even matter? The code works. It just throws the error every time I start the app on the wrong page (any page other than the page where the input actually exists). When I turn off debugging and throw the app up on the web (AWS Elastic Beanstalk), will my end users even notice the warning? Any long term issues with just ignoring this?
I am going to describe my setup anyway on the off chance that it triggers something in someone:
app.py - has fixed navigation in the form of two dropdowns (year and entity). Layout looks something like:
app.layout = html.Div(
[
dcc.Store(id="store", data = {}, storage_type = "session"),
html.Div(
[
dcc.Dropdown(
id="entity-dropdown",
multi=False,
clearable=False,
),
dcc.Dropdown(
id="year-dropdown",
multi=False,
clearable=False,
),
. . . rest of navigation . . .
]
),
html.Div(
[
dbc.Nav(
[
dbc.NavLink(
"Page1",
href="/",
className="tab",
active="exact"
),
... more pages . . .
dbc.NavLink(
"Page6",
href="/page6",
className="tab",
active="exact"
),
]
),
dash.page_container,
]
)
]
)
There are 8 pages at the top_nav level. Pages are hardcoded for formatting reasons. the @callback for year-dropdown has a bunch of logic for determining what set of years should be displayed.
Page6 (/page6) has two buttons, [‘Red’] and [‘Green’]. These buttons determine what charts are displayed on page 6, but they also must change the years that are displayed in ‘year-dropdown.’ So, i have the following callback in page6.py which: 1) determines whether or not to display the buttons at all depending on entity name &, if buttons should be displayed, sets the options and value and then captures the value to the dcc.Store variable:
@callback(
Output("radio-options", "options"),
Output("radio-value", "value"),
Output("store", "data"),
Input("entity-dropdown", "value"),
Input("radio-value", "value"),
supress_callback_exceptions = True
)
def radio_selector(entity: str, radio_value: str):
... logic deterimining whether radio buttons should be displayed depending on entity name
and then setting options and value. . .
store_value = radio_value
return radio_options, radio_value, store_value
The @callback for dropdown-year in app.py then reads the store and adjusts the years displayed in the dropdown accordingly.
This all works! Except for the error. Spent an hour this morning trying to modify @AnnMarieW 's Multipage Store example to fit my use case, but couldn’t replicate my issue.
Does anyone have any other suggestions? I’m not even married to the idea of using dcc.store (it is the only thing I am using it for). I just need to get a single string variable set by a callback in page6.py to a callback in app.py. If there is another way to do this, please let me know!