Storing intermediate data from a loop without using global variable

I have a callback function which looks like:

def myfunc:
   for loop :
     df = calculation
     # how update current value of counter and dataframe df without using global

Usually one would return to the output and it would be stored and can be called from another function using State. I can use global and can get current value but that is not a good approach. What’s better way to send the current value to a hidden-div or Store? can we use another function or yield?

For small amounts of data (less than 5MB), I would use dcc.Store as outline in the docs. Otherwise, I highly recommend using @Emil 's awesome dash-extensions package detailed in this thread.

Thanks for the response but how can I keep returning output within a loop. it would stop the loop right away. Otherwise, I would’ve returned it to

Ah sorry, I misunderstood your question. I’m not sure how dash would handle a yield statement, have you tried with a simple example outputting to dcc.Store?
Can you provide some additional details on your use case? There are some rare instances where using a global variable is an okay workaround.

I’m having a similar challenge. I’m attempting to output values, but an entire dataframe.
That said, I think the steps are 1) generate the output 2) store it as a object 3) call the data from the into a second call back. Would that prevent the loop from breaking in your case?