Error updating dbc.progress

Hello, I have two issues when trying to update the progress bar as functions are executed. The progress bar always reaches 100%, and I apologize for the disorder – I’m very new to this.

Hi @brianrodriguezvivas, welcome to the community.

You are returning constants, 100 and “100%” .

The progress does not work as you expect it to work, take a look at the last example here:

https://dash-bootstrap-components.opensource.faculty.ai/docs/components/progress/

Hello, I have already tried everything, I have not been able to update the bar every time a function runs, I left the constant at the end alone at the end as a test, I did not understand the examples well on how to dynamically update that
I appreciate your comment

Does this example help?

1 Like

I tried like this and it doesn’t work, it doesn’t update

barra_progreso =html.Progress(
                    id="progress_bar",
                    value="0",
                    style={'width': '100%'}
                )

#-----------------------------Callback de medición V-C----------------------------
@app.callback(
    outputs=[Output("grafico", "figure"),
    Output("resultado-alert", "children"),
    Output("grid", "rowData"),],
    inputs=Input("btn_medir_V-C", "n_clicks"),
    background=True,
    progress=[
        Output("progress-bar", "value"),
        Output("progress-bar", "max"),
    ],
    prevent_initial_call=True,
)
#-----------------------------Función de medición V-C----------------------------
def medir_callback(set_progress,n_clicks):

    total = 100
    set_progress((str(0),str(100)))
    IP_fuente = "192.168.0.100"
    inst = Conectar_Fuente(IP_fuente)
    measurement_voltage_Voc = Obtener_Voc(inst)
    set_progress((str(10),str(100)))

    Poner_Fuente_Voltaje(inst, 0)
    set_progress((str(30),str(100)))

    new_df = Barrido_IV(inst, 0, measurement_voltage_Voc, 6)
    set_progress((str(80),str(100)))
    inst.close()

    new_df = new_df.rename(columns={new_df.columns[0]: f'{new_df.columns[0]}_{n_clicks}',
                                    new_df.columns[1]: f'{new_df.columns[1]}_{n_clicks}'})

    dm.append(new_df)
    
    set_progress((str(90),str(100)))
    
    fig = graficar("Curva I-V TEC-12706", dm, "V", "A")

    lista_VOC.append(html.P(f"Voc medido: {measurement_voltage_Voc} V"))
    lista_VOC.append(html.Hr())
    set_progress["value"] = 95

    G1 = pd.concat(dm, axis=1)
    
    set_progress((str(100),str(100)))

    # Devolver tanto los datos del DataFrame como el gráfico
    return fig, lista_VOC, G1.to_dict("records")


Hey @brianrodriguezvivas it’s quite difficult to help you as I can’t reproduce your issue. I changed the callback of my example so that it is similar to yours:

@callback(
    output=Output("paragraph_id", "children"),
    inputs=Input("button_id", "n_clicks"),
    background=True,
    running=[
        (Output("button_id", "disabled"), True, False),
        (Output('modal', 'is_open'), True, False)
    ],
    progress=[
        Output("progress_bar", "value"),
        Output("progress_bar", "max")
    ],
    cancel=Input("cancel_button_id", "n_clicks"),
    prevent_initial_call=True
)
def update_progress(set_progress, _):

    time.sleep(1)
    set_progress(('25', '100'))
    time.sleep(1)
    set_progress(('50', '100'))
    time.sleep(1)
    set_progress(('75', '100'))
    time.sleep(1)
    set_progress(('100', '100'))

    return 'finished'

The progress bar behaves as expected. Maybe you could substitute your requests with time.sleep() just for testing?.

Are you running your app with debug=True? Do you get any errors?