Description
When using pattern matching for the running
argument (ex: running=[(Output({'type': 'loading', 'id': ALL}, 'display'), 'show', 'hide')]
), if there are no components on the page dash throws the error: state.paths.objs[idKey] is undefined
Describe your context
Please provide us your environment, so we can easily reproduce the issue.
- replace the result of
pip list | grep dash
below
dash 3.0.4
Describe the bug
When using pattern matching for the running
argument (ex: running=[(Output({'type': 'loading', 'id': ALL}, 'display'), 'show', 'hide')]
), if there are no components on the page dash throws the error: state.paths.objs[idKey] is undefined
Expected behavior
No error, no side updates (since there are no components)
Minimum Working Example
import dash
from dash import Dash, html, dcc, callback, Output, Input, Patch, ALL, callback_context
import time
import random
app = Dash(use_pages=True, pages_folder="")
home_page_layout = html.Div([
dcc.Loading(
html.Div(id={'type':'scorecard', 'id': 'home1'}),
id={'type': 'loading', 'id': 'home1'}
),
dcc.Loading(
html.Div(id={'type':'scorecard', 'id': 'home2'}),
id={'type': 'loading', 'id': 'home2'}
)
])
other_page_layout = html.Div('Other')
dash.register_page('home', path='/', layout=home_page_layout)
dash.register_page('blank', path='/blank', layout=other_page_layout)
app.layout = html.Div([
dcc.Store(id='data'),
html.H1(children='Title of Dash App', style={'textAlign':'center'}),
html.Div([
html.Span([
dcc.Link(f"{page['name']} - {page['path']}", href=page["relative_path"]), ' | '
]) for page in dash.page_registry.values()
]),
html.Button('Reload Data', id='reload-data'),
dash.page_container
])
@callback(
Output('data', 'data'),
Input('reload-data', 'n_clicks'),
prevent_initial_call=True,
running=[(Output({'type': 'loading', 'id': ALL}, 'display'), 'show', 'hide')]
)
def get_data(n_clicks):
time.sleep(3)
return random.randint(0, 10)
@callback(
Output({'type': 'scorecard', 'id': 'home1'}, 'children'),
Input('data', 'data'),
prevent_initial_call=True
)
def scorecard1(data):
return f'Data: {data}'
@callback(
Output({'type': 'scorecard', 'id': 'home2'}, 'children'),
Input('data', 'data'),
prevent_initial_call=True
)
def scorecard2(data):
return f'Data squared: {data * data}'
if __name__ == '__main__':
app.run(debug=True)
In this example, pressing the "Reload Data" button on the second page (/blank) throws the error as the loading elements are all on the first page