Black Lives Matter. Please consider donating to Black Girls Code today.

Problem when trying to share df between callbacks

Tried to follow the examples from the tutorial and this answer but still no luck. Specifically, I’m trying to use Example 2 - Computing Aggregations Upfront from the tutorial. A dataframe is created from a dropdown menu & used to create several graphs & tables. What I have so far is:

app.layout = html.Div(style={'backgroundColor': colors['background']}, children=[
    children='Aggregrate Prices for 12 month period',
        'textAlign': 'center',
        'color': colors['text']

        {'label': 'Value1', 'value': 'ABC'},
        {'label': 'Value2', 'value': 'DEF'},
        {'label': 'Value3', 'value': 'GHI'},
        {'label': 'Value4', 'value': 'JKL'}




Feedback from the terminal suggested to add the line below because I don’t have a layout property/figure for the callback that’s used to create the dataframe.


The feedback from the terminal without the above line

Attempting to assign a callback to the component with the id "intermediate-value" 
but no components with id "intermediate-value" exist in the app's layout.
If you are assigning callbacks to components that are generated by other callbacks
(and therefore not in the initial layout), then you can suppress this exception by 
setting `app.config['suppress_callback_exceptions']=True`.

The callback

@app.callback(Output('intermediate-value', 'children'), [Input('my-dropdown', 'value')])
def clean_data(selected_dropdown_value):

    print('clean_data') ###THIS ISN'T BEING PRINTED IN TERMINAL###

    df = pd.read_csv('...')
    df_1 = df.copy()
    df_2 = df.copy()
    df_3 = df.copy()


    datasets = {
         'df_1': df_1.to_json(orient='split', date_format='iso'),
         'df_2': df_2.to_json(orient='split', date_format='iso'),
         'df_3': df_3.to_json(orient='split', date_format='iso'),

    return json.dumps(datasets)

if __name__ == '__main__':

Right now I never get the string ‘clean_data’ printed in the terminal so the function isn’t running? But if I change the callback to below & use it to create the graph it works just fine & I see all the output in the terminal?

@app.callback(Output('my-graph', 'figure'), [Input('my-dropdown', 'value')]) 

Can’t understand why it’s not running with the intial callback Output(‘intermediate-value’, ‘children’)? After making this change, I’m required pull extra dfs for each graph/table but I’m using the same df for them all. I never have a global df shown in this answer, my df comes strictly from the dropdown selection. I don’t know if that’s the problem or if I’m missing something else?