A nonexistent object was used in an `State` of a Dash callback

I am using this tutorial (Dash CRUD App with PostgreSQL - Part 2 - YouTube) to connect to my postgres db and retrieve some table.
I now want to export my table in csv file but I’m getting “A nonexistent object was used in an State of a Dash callback”
when I run the application. Now, I am new to Dash and a bit confused, I understand that State does not trigger callback, so why is it triggering this error? The error gets triggered on table object.

You need to send some code for it to be easier to understand.

Hi, this is probably an easy fix but I am encountering the same issue as stated in the discussion while trying to load a page with dropdowns that have a default value set, using the ‘valaue’ property of dcc.Dropdown.

A simplified version of the code:

html.Div([
dbc.Row([
             dbc.Col([
                 dcc.Dropdown(id='data-scaling-technique',persistence = True,
                         
                         style={'color': 'black'},
                         persistence_type = 'session',value='standard-scaler',disabled=True)
                 ],width={'size':3})
             ]),
dbc.Row([dbc.Col([
                dcc.Dropdown(id='class-balancing-technique',
                         
                         style={'color': 'black'},
                         persistence = True,
                         persistence_type = 'session',
                         value='smote',disabled=True),
                
                ],width={'size':3})
                ])
])

the respective callbacks that I wrote for each of these dropdowns are:

##class balancing

    
@app.callback(Output('intermediate-data','data'),
               Input('training-data','data'),
               [
                State('class-balancing-technique','options')],
             )
def class_balance(data,value):
    if data is None or value is None:
        raise PreventUpdate
    
    else:
        
        data = pd.DataFrame(data)
        balanced_df=class_balance_method(df=data,method=value)
        print("balanced_data",balanced_df.shape)
        return balanced_df.to_dict("records")
        

##scaling

@app.callback(Output('processed-data','data'),
               Input('intermediate-data','data'),
              [
               State('data-scaling-technique','options')]
              )
def data_scale(data,value):
    if data is None or value is None:
        raise PreventUpdate
        
    
    else:
        
        data = pd.DataFrame(data)
        scaled_df=feature_scaling(df=data,scaling_method=value)
        return scaled_df.to_dict("records")

On page reload, I am constantly shown this error, even though I think the components are present in the layout.

A nonexistent object was used in an State of a Dash callback. The id of this object is data-scaling-technique and the property is options. The string ids in the current layout are: [stored-data, training-data, intermediate-data, processed-data, url, page-content]

Any help would be appreciated, Thank you in advance! <3

Hi,

From the error message:

A nonexistent object was used in an State of a Dash callback. The id of this object is data-scaling-technique and the property is options . The string ids in the current layout are: [stored-data, training-data, intermediate-data, processed-data, url, page-content]

It looks to me that you have a multipage app, therefore the component is not present in the initial layout. Please take a look on this piece of the docs on how to add a layout validation and avoid this error.

Please also be mindful when writing questions and not simplify too much the code, as in this case where the error is related to the multi-page app part and this is never mentioned or showed in the code.

You are right. It is a multi-page app. I shall be mindful in the future while framing my questions, thanks for the input! I will try this solution out.

1 Like