-
Notifications
You must be signed in to change notification settings - Fork 40
Open
Description
Hi, I'm not sure if this is a Pages plugin issue or dcc.Store. I have a two page demo. One page accepts an email, the associated callback outputs the email to a store and forces a redirect:
login.py
email = dcc.Input(id='email', name='email', type='email', placeholder="Enter email")
button = html.Button('Sign In', type='submit', id='btn')
redirect = dcc.Location(id='redirect', refresh=True)
layout = html.Div([email, button, redirect])
@callback(Output('redirect', 'href'), Output('store', 'data'), State('email', 'value'), Input('btn', 'n_clicks'))
def email_cb(email, clicks):
_redirect = NO_UPDATE
_store = NO_UPDATE
if clicks:
_redirect = '/user'
_store = {'email' : email}
return _redirect, _store
The user page has a callback that accepts the stored email value and updates the page:
user.py
@callback(Output('user', 'children'), Input('store', 'data'))
def _login_cb(data):
print('_login_cb')
ctx = callback_context
if not ctx.triggered:
print(' NOT triggered')
if data:
print(' Valid store data available')
return f"Hello {data['email']}"
else:
return NO_UPDATE
The page updates with the email correctly. The problem is ctx.triggered is false even when valid store data is available. The print message output is:
_login_cb
NOT triggered
Valid store data available
app.py
store = dcc.Store('store', storage_type='session')
app = dash.Dash(
__name__, plugins=[dl.plugins.pages], external_stylesheets=[dbc.themes.BOOTSTRAP]
)
app.layout = dbc.Container(
[store, dl.plugins.page_container],
fluid=True,
)
Any ideas?
FarsanRashid
Metadata
Metadata
Assignees
Labels
No labels