【发布时间】:2019-12-09 02:10:46
【问题描述】:
我已经看到了 Progress 和 Interval 组件在 Dash 中显示进度的示例:
import dash_bootstrap_components as dbc
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output
progress = html.Div(
[
dcc.Interval(id="progress-interval", n_intervals=0, interval=500),
dbc.Progress(id="progress"),
]
)
@app.callback(
[Output("progress", "value"), Output("progress", "children")],
[Input("progress-interval", "n_intervals")],
)
def update_progress(n):
# check progress of some background process, in this example we'll just
# use n_intervals constrained to be in 0-100
progress = min(n % 110, 100)
# only add text after 5% progress to ensure text isn't squashed too much
return progress, f"{progress} %" if progress >= 5 else ""
但是,我找不到任何实际显示如何将进度条正确链接到某个后台进程的示例。
例如,如果我有一个带有常规 for 循环的回调,我如何显示这个 for 循环的进度(即,如果我在 100 的第 10 个元素上,我希望它显示进度条中的 10%)?
【问题讨论】:
标签: python plotly-dash