Dynamic link need to be reloaded to appear

Hi ! First I failed to find some answers on my issue, and that’s why I decided to ask my (rather) basic questions here.

I have a implemented multipage questionary. Depending the answer of a question answered in a previous webpage and stored into a dictionary through dcc.StoreI would like to generate a different dcc.link. The problem is that I need to refresh the webpage to make the link appears.

I spend quite a lot of time trying to solve this basic issue but I failed. Do you have any idea how to make this works ?

First, the data dictionary is declared as follow in the main.py piece of code :

import dash
from dash import dcc, html
import dash_bootstrap_components as dbc

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

server = app.server

app.prevent_initial_callbacks='initial_duplicate'

app.suppress_callback_exceptions=True

app.layout = html.Div([
    dbc.Container(
    [dash.page_container],
    fluid=True
    ),
    dcc.Store(id='record_answers', storage_type='local', data = {})
])

if __name__ == "__main__":
    app.run_server(debug=True) 

On page 6 of my questionary, I generate and update the dcc.link as follow :

layout = html.Div(id='dynamic-link')

@callback(
    Output('dynamic-link', 'children'),
    Input('record_answers', 'data')
)

def update_link(data):
    if 'consent' not in data:
        return html.Div()  
    if data['consent'] == 'yes':
        return dcc.Link('Next page', href='/page-7', style={'font-size': '20px'})
    elif data['consent'] == 'no':
        return dcc.Link('Access your personal report', href='/page-8', style={'font-size': '20px'})

Thanks in advance !

Hey there, what do you mean by “refresh”? And what by “appear”?

Sorry for the confusion. “refresh” means reload and by “appear” I mean that the links are supposed to be displayed immediately when the webpage is initial loaded according the answer to a previous question.

Looking only at the code, it seems that when page 6 is loaded, record_answers data is not changed → the callback is not triggered → update_link() is not executed → no dcc.Link added to dynamic-link div. I’m actually not sure why the callback gets triggered when you reload the page; might be due to code that is not shown here. Is this full code for page 6?

Also, why are you generating links this way? Are you trying to prevent the user from proceeding to the next page before answering a specific question?

The rest of the layout has no impact on the problem. Thank you for your thoughts !