Black Lives Matter. Please consider donating to Black Girls Code today.
Dash HoloViews is now available! Check out the docs.

How do I use radio buttons to update a fig.layout setting?

Hi, I’m trying to update the frame duration setting of an animated plot using Dash radio buttons. It works if I refresh the browser manually but I’d like to either not have to refresh (so the duration updates on the fly - may not be possible) or to force a refresh/reload so that the new setting takes effect and the graph is re-rendered with the new setting. Here’s the relevant part of my code, what do I need to change?:

app = dash.Dash(__name__, external_stylesheets=[dbc.themes.CYBORG])
app.layout = html.Div([
        {'label': 'Slow', 'value': 250},
        {'label': 'Medium', 'value': 150},
        {'label': 'Fast', 'value': 100}
    labelStyle={'display': 'inline-block'}
    dcc.Graph(figure=fig, id='graph')

@app.callback(Output('graph', 'figure'),
    [Input('radio-items', 'value')])
def update_duration(value):
    fig.layout.updatemenus[0].buttons[0].args[1]["frame"]["duration"] = value
    return fig

app.run_server(debug=False, use_reloader=False)