Duplicate Output callback with dash pages

Hello I’m using Dash pages, I put callbacks in one of my pages and it return me the error “Duplicate output callback” for every callback I’ve done, I verified many times there isn’t others callback using same id and didn’t found them in the pages or in the import.

I think dash understand it as if I call the callback in the pages.py and in the app.py that call pages, because if I moove callbacks from the pages to the app, it works fine, and it seems to works well if I put my callbacks in the 2 files.

I could let like this but I’ve already do many dash app with pages and never see this problem before.
The only difference with the apps that work is I import a flask login, I don’t know if you know what could be wrong.

Here’s is my code :
app.py

def create_session():
    engine = create_engine("postgresql+psycopg2://{}:{}@{}:{}/{}".format(
        DB_USER, DB_PASSWD, IP_ADDRESS, PORT, DB_NAME
    ))
    session = sessionmaker(bind=engine)
    return session()
session = create_session()

config = configparser.ConfigParser()

app = Dash(__name__, use_pages=True, external_stylesheets=[dbc.themes.BOOTSTRAP])
server = app.server
app.config.suppress_callback_exceptions = True
# config
server.config.update(
    SECRET_KEY=os.urandom(12),
    SQLALCHEMY_DATABASE_URI='sqlite:///data.sqlite',
    SQLALCHEMY_TRACK_MODIFICATIONS=False
)
# Setup the LoginManager for the server
login_manager = LoginManager()
login_manager.init_app(server)
login_manager.login_view = '/login'
#User as base
# Create User class with UserMixin
class Users(UserMixin, Users):
    pass

app = Dash(__name__, use_pages=True, external_stylesheets=[dbc.themes.BOOTSTRAP])

navbar = dbc.NavbarSimple(
    children=
    [
        dbc.NavItem(dbc.NavLink(html.H1(page['name']), href=page["relative_path"]))
        for page in dash.page_registry.values()
    ],
    brand=html.Div([
        html.H1("Dash prototype by Datalyo ", style = {"display" : "flex "}),
        #html.Img(src = "https://media.licdn.com/dms/image/C4D0BAQGAMwTwOiaOig/company-logo_200_200/0/1591944753716?e=1682553600&v=beta&t=Di3xpy_BGFAWQFE_biH58j8v-FityJs5MQRoJ9YVRS4", style = {"zoom" : 0.4})
        html.Img(src = "assets/logo.png", style = {"zoom" : 0.5})
    ],className="d-flex"),
    color="warning",
    dark = False
)

app.layout = html.Div([

    navbar,
	dash.page_container
    
])

login.py

dash.register_page(__name__)

login = html.Div([dcc.Location(id='url_login', refresh=True)
            , html.H2('''Please log in to continue:''', id='h1')
            , dcc.Input(placeholder='Enter your username',
                    type='text',
                    id='uname-box')
            , dcc.Input(placeholder='Enter your password',
                    type='password',
                    id='pwd-box')
            , html.Button(children='Login',
                    n_clicks=0,
                    type='submit',
                    id='login-button')
            , html.Div(children='', id='output-state')
        ])
layout = login

@callback(
    Output('url_login', 'pathname')
    , [Input('login-button', 'n_clicks')]
    , [State('uname-box', 'value'), State('pwd-box', 'value')]
    ,prevent_initial_call = True)
def successful(n_clicks, input1, input2):
    print(n_clicks)

If you have some idea why that don’t work I would be very gratefull!

Have a nice day!

You have this called twice. Could that be the problem?

1 Like