Dash Python 应用程序按钮用于操作和刷新页面

hag*_*wal 5 python python-3.x plotly-dash

Dash App 中需要有一个回调函数来执行某些操作然后刷新页面,只能使用 HTML A 标签实现页面重新加载。

html.A(html.Button('Refresh Data'),href='/')
Run Code Online (Sandbox Code Playgroud)

必需的:

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 ?
Run Code Online (Sandbox Code Playgroud)

Hey*_*Man 6

我想这是正确的方法:

将其添加到您的布局中:

dcc.Location(id='url', refresh=True),
Run Code Online (Sandbox Code Playgroud)

打回来:

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


Tom*_*Tom 0

这应该可以满足您的需要:

html.A(html.Button('Refresh Page'),href='/'),
Run Code Online (Sandbox Code Playgroud)