Confused about callback triggers/callback order

Hi all,

I’m using the file picker tree in my application, as shown in this forum post: File Explorer Tree Generator for local files.

I’ve modified it so individual files at the end of the tree are buttons. I have two callbacks in my app right now:
1st checks which button is pressed and saves the clicked file-path into a dcc.Store.
2nd callback cleans and creates data from the selected file path, then puts that data in a separate dcc.Store.

It seems like my 2nd callback isn’t triggering. My buttons do link me to another page to display results, but the “create_wafer_data” is never triggered, as I don’t see the “CREATING NEW DATA” print statement. I believe the first callback should be properly storing the file path, as previously, I had the button send me to the “results” page, with a simple dmc.Text that displayed which filepath was selected.

Does anybody have pointers as to what could be causing this?

Here’s some short code snippets of my callbacks:
1st Callback:

# Callback to store the selected file path
@callback(
    Output('selected-file-path', 'data'),
    Input({'type': 'file-item', 'index': ALL}, 'n_clicks'),
    State({'type': 'file-item', 'index': ALL}, 'id'),
    prevent_initial_call=True  # Prevent the callback from being called on initial load
)
def store_selected_file(n_clicks, ids):
    if not n_clicks or all(click is None for click in n_clicks):
        return dash.no_update

    # Find the index of the most recently clicked button
    clicked_index = max(range(len(n_clicks)), key=lambda i: n_clicks[i] if n_clicks[i] is not None else -1)
    
    # Ensure that the button was actually clicked (n_clicks > 0)
    if n_clicks[clicked_index] > 0:
        print("STORING NEW DATA")
        selected_file_path = ids[clicked_index]['index']
        return selected_file_path

    return dash.no_update

2nd Callback:

@callback(
    Output("wafer-data", "data"),
    Input("selected-file-path", "data"),
    prevent_initial_call=True
)
def create_wafer_data(selected_csv_path):
    print("CREATING NEW DATA")

dcc.Store within my app.py

app.layout = html.Div(
    [
        create_appshell(dash.page_registry.values()), 
        dcc.Store(id="selected-file-path", data="", storage_type="memory", clear_data=True),
        dcc.Store(id="wafer-data", data="", storage_type="memory", clear_data=True)
    ]
)

Thank you for taking the time to look at my post :slight_smile:

My thought process is as follows:
If callback #1 is triggered (e.g., I see “STORING NEW DATA”), I figured that this would change the Input of callback #2 and trigger callback #2, and should show me “CREATING NEW DATA”.

This line in the documentation of Basic Callbacks leads me to believe this, however my application currently isn’t acting this way:

  1. The “inputs” and “outputs” of our application are described as the arguments of the @callback decorator.
    a. By writing this decorator, we’re telling Dash to call this function for us whenever the value of the “input” component (the text box) changes in order to update the children of the “output” component on the page (the HTML div).