Dash:读取文件的进度条

Val*_*ria 6 python plotly-dash

我已经看到了这个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 ""
Run Code Online (Sandbox Code Playgroud)

但是,我找不到任何实际显示如何将进度条正确链接到某个后台进程的示例。

例如,如果我有一个带有常规for循环的回调,我该如何显示这个for循环的进度(即,如果我在 100 中的第 10 个元素上,我希望它在进度条中显示为 10%)?

Ada*_*der 3

@Valeria,我创建了一个关于进度条和微调器的教程,重点关注加载器的格式。https://youtu.be/t1bKNj021do

但是对于进度条与后台进程的链接,这个人很好地创建了一个示例应用程序和代码。https://github.com/tcbegley/dash-rq-demo