from Stackoverflow: triggers - Python plotly-dash @app.callback()-function isn't triggered. What should I do? - Stack Overflow (I’ve gotten no answer to this)
I am programming a multi-page app with Python dash-plotly. My app.py-program has the following layout structure:
app = dash.Dash(__name__)
url_bar_and_content_div = html.Div([
dcc.Location(id='url', refresh=True),
html.Div(id='page-content'),
dcc.Store(id='store1', storage_type='memory'),
dcc.Store(id='store2', storage_type='memory')
])
layout_page1 = html.Div([ ... ])
layout_page2 = html.Div([
...
html.Div([
html.Button(id='submit-button',
n_clicks=0,
children='Submit',
style={'background-color': '#84cc32', 'color': 'white'}
)], className="assay__element"),
...
dcc.Store(id='page2-storage-1', storage_type='memory'),
dcc.Store(id='page2-storage-2', storage_type='memory'),
])
# so 2 pages in total
# index layout
app.layout = url_bar_and_content_div
# "complete" layout
app.validation_layout = html.Div([
url_bar_and_content_div,
layout_page1,
layout_page2
])
# amongst callback-functions and hidden Divs in layout_pages etc.
The structure basically follows the 3rd code example of the doc page URL Routing and Multiple Apps | Dash for Python Documentation | Plotly 1-to-1!
So at the moment I am trying, amongst other things, to transfer the two stored datas (‘page2-storage-1’ and ‘page2-storage-2’) of layout_page2 to url_bar_and_content_div (‘store1’ and ‘store2’), and here is where I’m failing:
@app.callback([Output('store1', 'data'), # simplified! (unnecessary lines discarded)
Output('store2', 'data'),
...,
Output('submit-button', 'n_clicks')], # the "Submit"-button of page 2
Input('submit-button', 'n_clicks'), # it gets triggered by a click
[State('page2-storage-1', 'data'),
State('page2-storage-2', 'data')])
def submit_to_page1(n, stored_1, stored_2):
if n>0:
if stored_data is not None:
#print(stored_1)
#print(stored_2)
return stored_1, stored_2, ...
return dash.no_update, dash.no_update, ...
return dash.no_update, dash.no_update, ...
@app.callback(Output(...),
[Input('store1', 'data'),
Input('store2', 'data')],
State(...),
prevent_initial_call=False)
def to_page2(stored_1, stored_2, ...):
#print(stored_1)
#print(stored_2)
print("Hey")
do stuff
return ...
The FIRST callback works, it is triggered by a click on an html-Button() on page 2, and as a reaction sends/returns the two saved datas (‘page2-storage-1’ and ‘page2-storage-2’) to the save places of the index layout (‘store1’ and ‘store2’). I have of course tested if the callback worked, as is seen in the code, by having added those two command lines print(stored1&2) to see if the data were really received (It was!).
The SECOND callback is NOT working, and I don’t know why. In the parameters of to_page1, I first wrote prevent_initial_call=False, so that the callback would be executed in the initial call, and I also printed the storage places of the index layout (to which the datas in the first callback are returned, those outputs) and at the start they were indeed both empty!
So that must mean that this callback should be triggered because its two inputs were empty before but then received the data from the former callback! So why doesn’t it get triggered then??
When I disable the initial call prevention, the callback function never gets triggered, it never executes, I know because the printed text “Hey” never appears on the console. So why is it? Did the dcc.Stores of url_bar…div get filled at some point time, or does the returned data really Not reach the two save slots? Or is it some issue that I’m sending two input datas at the same time or something like that, or even some syntax issue??
How do I know?? How can I find out what the reason is that the latter callback does not get triggered?? Are there some attributes, or commands etc. I could use that could help me in a way?
There is another callback that isn’t getting triggered too, but it’s more or less the same situation like this one here, so I could fix them both.
I’d be very thankful if someone here responds to my issue, I’d appreciate the help! Thanks in advance!