简体   繁体   中英

Dash Python App Button for action and refresh the page

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 ?

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='/'),

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM