DashLogger with time intervals

Hi, I’d like to set time intervals between several Dash loggers.
but all the loggers just keep popping up simultaneously.

for example, just an simplified code:

import dash_mantine_components as dmc
from dash_extensions.enrich import Output, Input, html, DashProxy, LogTransform, DashLogger
import time

app = DashProxy(transforms=[LogTransform()], prevent_initial_callbacks=True)
app.layout = html.Div([dmc.Button("Run", id="btn"), dmc.Text(id="txt")])

@app.callback(Output("txt", "children"), Input("btn", "n_clicks"), log=True)
def do_stuff(n_clicks, dash_logger: DashLogger):
    dash_logger.info("first info")
    dash_logger.info("second info")
    return '/'

if __name__ == '__main__':

My goal is to pop up “first info”, then wait 5 seconds, and then pop up “second info”
but somehow two loggers pop up together… I don’t get it.
Is there any solutions for this issue?

The DashLogger returns the logs to the frontend only when the callback ends, so what you are trying to do, it not possible. If you need to display logs “as you go”, you would need a different architecture. One option would be to run the calculation (i.e. the current content of you callback) async, post the logs to some cache, and then poll the logs (e.g. using an Interval component) to the UI

1 Like