python - Dash Loading children - 页面刷新后内容的持久性
问题描述
我有以下 Dash 应用程序,其中回调函数有一些由按钮触发的逻辑,它更新 html.Div 组件的内容(id="run-button-feedback")并刷新页面。但是,我无法避免 html.Div 组件在页面刷新后返回其初始值。
页面刷新对于其他组件的更新是必不可少的,但是这个 html.Div 组件需要包含一条给用户的消息,该消息在页面刷新后仍然存在
我怎样才能做到这一点?
import dash
import dash_core_components as dcc
import dash_html_components as html
import dash_bootstrap_components as dbc
from dash.dependencies import Input, Output, State
app = dash.Dash(__name__, external_stylesheets=[dbc.themes.GRID])
app.config.suppress_callback_exceptions = True
server = app.server
app.layout = dbc.Container([
dcc.Location(id="url", refresh=False, href='home/page/'),
dbc.Row([
dbc.Col([
html.Span(
"RUN",
id="run-button",
n_clicks=0,
className="button",
),
]),
dbc.Col([
dcc.Loading(
id="run-button-loading",
children=[
html.Div(id="run-button-feedback")
],
type="circle",
),
])
]),
], style={"margin": "0%"}, fluid=True) # fluid=True for Container to fill horizontal space and resize fluidly
# callback logic
@app.callback(
[Output('url', 'pathname'),
Output('run-button-feedback', 'children')],
[Input('run-button', 'n_clicks')],
[State('url', 'pathname')],
)
def refresh_analysis(n_clicks, url):
"""
Refresh page on which it was called
"""
if n_clicks > 0:
return url, "message that need to persist after page refresh <p>clicked {} times</p>".format(n_clicks)
return url, "Initial value"
if __name__ == '__main__':
app.run_server(debug=True)
解决方案
推荐阅读
- python - 未找到 pytest 夹具“狗”
- variables - 我可以在 ADF 中使用设置变量来生成给定开始日期和结束日期之间的日期数组吗?
- android - 使用翻译将视图移动到屏幕底部
- java - 您可以通过Java中的超类访问子类变量吗
- r - 使用 ggplot r 将多个箱线图组合成一个图形
- r - 如何解决要求 .stargazer.wrap 功能的观星者错误
- python - 最佳匹配点(减去 2 个数组)
- python - 配置 Python setup.py
- cassandra - 如何仅按主键集中的一列总结 cassandra 计数器分组?
- python - BeautifulSoup:为什么我收到内部服务器错误?