Persistence not working with page refresh

I’ve used Dash and persistence=True for about five years. However with a new simple program it doesn’t seem to be working properly with dcc.RadioItems. On every page reload, the value switches back to the original value=‘value’ setting, in this case ‘A’.

Please let me know if I need to make a change or have a misunderstanding on persistence across page refreshes.

from dash import Dash, html, dcc, callback, Output, Input

app = Dash()

app.layout = [
    html.Div(className='row', children=[
        dcc.RadioItems(id='radio_abc',
                       options=['A', 'B', 'C'],
                       value='A',
                       inline=True,
                       persistence=True,
                       persistence_type='local')
        ], style={'display': 'inline-block'}),
    html.Div(id='div_abc')
]

@callback(
    Output(component_id='div_abc', component_property='children'),
    Input(component_id='radio_abc', component_property='value'),
)
def update_graph(abc):
    return abc


# Run the app
if __name__ == '__main__':
    app.run()

Hy @marketemp. The issue is that your layout is defined as a list instead of a single component. If you define the layout as a list of components, persistence doesn’t work properly.

The example below work fine for me:

from dash import Dash, html, dcc, callback, Output, Input

app = Dash()


app.layout = html.Div([
    html.Div(className='row', children=[
        dcc.RadioItems(
            id='radio_abc',
            options=['A', 'B', 'C'],
            value='A',
            inline=True,
            persistence=True,
            persistence_type='local'
        )
    ], style={'display': 'inline-block'}),
    html.Div(id='div_abc')
])

@callback(
    Output(component_id='div_abc', component_property='children'),
    Input(component_id='radio_abc', component_property='value'),
)
def update_graph(abc):
    return abc


# Run the app
if __name__ == '__main__':
    app.run()
2 Likes

Thank you so much.

I have no idea how my layout became a list, whether by accident or pasting something else. I never would have correlated that to be the persistence cause in a million years. Working great now!

1 Like

Thanks for the solution @Xavi.LL

This sounds like a bug to me… would you like to open an issue on GitHub?