ID not found in layout error but the ID is in the layout

Here is the minimial reproduceable example code for my multipage app
the problem is that i get 5 of the errors shown below on the page load and even more when i click on the buttons. the ids are clearly in the layout, they are not produced by some function.

Even wierder… this code worked fine yestderday!! when i came back today to continue working every single callback in my app on every page started giving me this error!! i have commented out all callbacks on other pages and only included the one shown here, but there was originally like 20+ of these errors. i switched browsers, and cleared all cache and cookies and everything, nothing will bring it back. im very confident no code was changed since yesterday.

The file in question is ./pages/login_page.py

./app.py

import argparse
import dash
import dash_bootstrap_components as dbc

app = dash.Dash(__name__, use_pages=True, pages_folder="./pages", assets_folder="./assets", external_stylesheets=[dbc.themes.BOOTSTRAP])

app.layout = dash.html.Div([
                            dash.page_container
                            ])



if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    parser.add_argument("--open-to-lan", action="store_true")
    args = parser.parse_args()

    if args.open_to_lan:
        app.run(host="0.0.0.0", debug=False)
    else:
        app.run(debug=True)

./pages/login_page.py

import dash
import dash_bootstrap_components as dbc

from dash import dcc
from dash import html
# from database_functions import add_user, authenticate_user
from exceptions import UserAlreadyExistsError

dash.register_page(__name__, title="Login", path="/login")


layout = html.Div([
                   html.Div(id="empty_for_callback"),
                   dbc.Modal([
                              dbc.ModalHeader(dbc.ModalTitle("Login failed")),
                              dbc.ModalBody("We could not log you in, double check your username and password"),
                             ], id="login_fail_popup"),
                   dbc.Modal([
                              dbc.ModalHeader(dbc.ModalTitle("Sign up failed")),
                              dbc.ModalBody("Username already in use, please pick another one"),
                             ], id="sign_up_fail_popup"),
                   html.H1("Crime View Login", id="login_page_title"),
                   html.Div([
                             html.Div([
                                       dcc.Input(placeholder="Username", type="text", debounce=True, id="username_input")
                                      ], id="username_input_container"),
                             html.Div([
                                       dcc.Input(placeholder="Password", type="password", debounce=True, id="password_input")
                                      ], id="password_input_container"),
                             html.Div([
                                       html.Button("Sign Up!", id="sign_up_button"),
                                       html.Button("Login!", id="login_button")
                                      ], id="login_submission_buttons_container")
                            ], id="login_components_container")
                  ], id="login_page_container")



@dash.callback(
    dash.Output("empty_for_callback", "children", allow_duplicate=True),
    dash.Output("sign_up_fail_popup", "is_open"),
    dash.Input("sign_up_button", "n_clicks"),
    dash.State("username_input", "value"),
    dash.State("password_input", "value"),
    prevent_initial_call="initial_duplicate"
)
def sign_up(n, username, password):
    print("SIGN UP")
    raise dash.exceptions.PreventUpdate
    # if not n:        raise dash.exceptions.PreventUpdate
    # if not username: raise dash.exceptions.PreventUpdate
    # if not password: raise dash.exceptions.PreventUpdate

    # try:
    #     add_user(username, password)
    # except UserAlreadyExistsError:
    #     return dash.no_update, True


    # dash.callback_context.response.set_cookie("username", username)
    # return dcc.Location(pathname="/crime-view", id="sucessful_sign_up_redirect"), False


@dash.callback(
    dash.Output("empty_for_callback", "children", allow_duplicate=True),
    dash.Output("login_fail_popup", "is_open"),
    dash.Input("login_button", "n_clicks"),
    dash.State("username_input", "value"),
    dash.State("password_input", "value"),
    prevent_initial_call="initial_duplicate"
)
def login(n, username, password):
    print("LOGIN")
    raise dash.exceptions.PreventUpdate
    # if not n:        raise dash.exceptions.PreventUpdate
    # if not username: raise dash.exceptions.PreventUpdate
    # if not password: raise dash.exceptions.PreventUpdate

    # if not authenticate_user(username, password):
    #     return dash.no_update, True

    # dash.callback_context.response.set_cookie("username", username)
    # return dcc.Location(pathname="/crime-view", id="sucessful_login_redirect"), False

Hey @SaltySodiums,

I’m not sure, but the problem might be that the app.py is within the pages folder.

apologies @AIMPED , that was a typo. app.py IS NOT in the pages folder. i have edited the post to reflect that.

I haven’t been able to reproduce the error - this code works perfectly for me. (Dash 2.16.1)

1 Like

@davidharris so its not a code problem then and is something related to my computer?