Say I have a for loop where each iteration only takes a short while and I want a dash figure updated in each iteration:

for i, (idx, row) in enumerate(df.iterrows()): update vector app.callback(Output('my-plot', 'figure'), [Input('vector')])

I have browsed online but there is apparently no way of doing this in dash it seems. My only solution is to use the Interval component and then the callback function retrieves some pickle files or something that are updated by running another kernel on my computer but there must be a better way.

Note: the idea is to have a graph that is updated 1 data point a time that is then appended to the graph - through Dash. Please, let me know how you would do it. It know I can just use the ordinary matplotlib.pyplot but I want a nice looking app and not matplotlib.

1 Answers

0
coralvanda On Best Solutions

Using Dash, if you want to update a component, then you need to use a callback. The Dash way to do this is, as you said, using an Interval component as the trigger for the callback.

The callback function could read in the file and check the total number of data points in it, and probably use the State value of the data being displayed so it can count how many data points are currently displayed. Each iteration, the function would add one more point from the file to the output until it reached the total number of data points in the file. If you have a file that some other program is changing during the operation of the Dash app, then the callback function will be able to read in the updated file each time it runs.