✊🏿 Black Lives Matter. Please consider donating to Black Girls Code today.
⚡️ Concerned about the grid? Kyle Baranko teaches how to predicting peak loads using XGBoost. Register for the August webinar!

Datalogging callback system

Hello, I was hoping to get some advice on how to configure a callback for logging live data into a CSV. I have live data coming in from 5 instruments which I want to continuously log to a single row in a CSV with a single timestamp for the entire row. Currently, I have 5 (1 for each instrument) separate callbacks that request data from their respective instrument at the same time, then a separate callback that takes the data as its 5 inputs and logs to a CSV. The problem I have is that after they have been requested, the data packets don’t all arrive at the same time. So if the first instrument sends its data 0.5s before the last instrument, the callback will fire and log only the first instrument to the CSV. Basically, I need the callback to wait until all 5 instruments have returned their data before it logs data to the CSV. Is there a simple way to do this?

I think that you could use dash.exceptions.PreventUpdate() to stop the callback from firing until all the values were populated:

def log_data(a, b, c, d, e):
    if None in [a, b, c, d, e]:
        raise dash.exceptions.PreventUpdate()
    # code to write to csv