Hi, I have an app where I need to load a value into an Input in some scenarios, but allow the user to update the input in other scenarios. When I use code to set the value the persistence does not work (ie when refreshing I lose the value), even though persistence is set to ‘local’. If the user inputs the value then the persistence does work (ie when refreshing the value remains).
Is there a solution to get persistence working when code sets the input value?
Please see sample code below.
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output, State
from dash.exceptions import PreventUpdate
app = dash.Dash(__name__)
app.layout = html.Div([
html.Button(id='test-button', children='Load Test Data'),
dcc.Input(id='test-input', debounce=True, persistence=True, persistence_type='local')
if dash.callback_context.triggered['prop_id'].split('.') == 'test-button':
return 'Button Clicked'
if __name__ == '__main__':
I think this may be related to the below post also:
More detail on the potential problem:
I’m not familiar with the workings of React so I’d be really happy if anyone can shed any light on whether there is a workaround for this, or if there isn’t and I should build my app with that in mind.
Can I revive this topic? Has this issue already been addressed in Dash, or is this on the road map to be addressed? Or are we dealing with an unsolvable problem?
The way I circumvent this problem is with the use of the dcc.store component. However this makes your callbacks and interactivity very clunky. I feel the logic would be much more streamlined if persistence would still work when values of components are updated via callbacks (since you can just use the persistence props instead of defining stores for each component)