Quantcast
Channel: 🎛️ Dash - Plotly Community Forum
Viewing all articles
Browse latest Browse all 6271

Custom progress information on each loop iteration in app.callback

$
0
0

@michlimes wrote:

Hi All,

One of my callback is a loop of quite long Python process. I’d like to send some progress information to users while it is running.

Below you will find my code which represent what I’d like to do - in HERE section i’d like to update div with progress update.

import dash
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output, State
import time

app = dash.Dash(__name__)

app.layout = html.Div(
    [
        html.Div('Not run', id='div-1'),
        html.Button('Run long process', id='button-1', n_clicks=0)
     ]
)

@app.callback(
    Output('div-1', 'children'),
    [Input('button-1', 'n_clicks')],
    [State('div-1', 'children')]
)
def run_long_process(n_clicks, curr_status):
    status = curr_status
    if n_clicks > 0:
        # run_long_process
        for iteration in range(10):
            #quite long process
            time.sleep(1)
            #HERE i'd like to update div-1 with status: "{iteration}/10 finished"
        status = "Finished"
    return status

if __name__ == '__main__':
    app.run_server(debug=True)

Posts: 2

Participants: 2

Read full topic


Viewing all articles
Browse latest Browse all 6271

Trending Articles