Dash Python App Button for action and refresh the page

Viewed 2957

Need to have a callback function in Dash App for performing some action and then refreshing the page, only page reload could be achieved using HTML A tag.

html.A(html.Button('Refresh Data'),href='/')

Required:

app.layout = html.Div([html.Button(id="refresh")])

@app.callback(Output('???', '???'),
          [Input('refresh', 'n_clicks')])
def refresh(n):
## Perform some action ##
## call python function API ##
## Finally Refresh the Page ##
 ?
return ?
2 Answers

I guess this is the proper way to do it:

add this to your layout:

dcc.Location(id='url', refresh=True),

callback:

@app.callback(
    Output("url", "href"),
    Input("App-logo", "n_clicks"),
    prevent_initial_call=True,
)
def reload_data(_):
    return "/"

This should do what you need:

html.A(html.Button('Refresh Page'),href='/'),
Related