The scenario is a multi-pages app with an input parameter (
dcc.Input with a given id) being present in more than one page, so that if you change the parameter in one page the change is reflected in all pages, because the parameter is memory persistent so that its value is lost on refresh but kept when switching between pages.
But what if I want to add query string initialization of the
dcc.Input parameter? The query string value is passed to the layout function as an argument,
def layout(my_parameter = <some_default_value>): return [ ... input_my_parameter(my_parameter), ... ]
where, as far as I understand, since I cannot define in two different layouts two dcc.Input elements with the same id, I have to enclose the dcc.Input definition in a pre-defined function that accepts the query_string_value as argument and returns the dcc.Input element with the value property set to query_string_value, as below;
def input_my_parameter(query_string_value): return dcc.Input( id='some_id', type="number", value=float(query_string_value), persistence = True, persistence_type = 'memory' )
With this solution you correctly get the parameter set to query string value when using query string in URL and set to default value when not, but when you switch page persistence is broken because layout receives
None as value of
my_parameter which therefore is set to default value instead of keeping current value.
Any clue on how to solve this issue?
Thanks in advance for your attention.