Dash Freezing due to callback time?

So i have this weird problem where my datatable cause the entire webpage to freeze and crash. I have singled out the code that causes the issue.

This is the output for the datatable

output = [
dict(CGName=a, OnStock=nice_numbers(b), BackLog=nice_numbers(c), OrdersPassed=nice_numbers(d),
**{param: e[n16n] for n16n, param in enumerate(next_weeks)})
for a, b, c, d, e in
zip(cg_name, cg_current_stock, cg_backlog_stock, cg_passed_stock, cg_stock)
And this is the function nice_numbers

def nice_numbers(number):
number = str(int(number))
clean_str = ‘’
for i in range(len(number)):
if i % 3 == 0:
clean_str = number[-(i+1)] + ‘,’ + clean_str
clean_str = number[-(i+1)] + clean_str
if clean_str[0] == ‘-’ and clean_str[1] == ‘,’:
clean_str = clean_str[0] + clean_str[2:]
return clean_str[:-1]

it seems to freeze when i have too many rows in the data. Is there something i am missing? If i remove the nice_numbers it does not freeze. So it seems that if the callback takes to long that the whole thing crashes.

Not sure what the rest of your code logic is but it seems you’re doing a lot of element-wise operations using a bunch of collections to “compile” them all into a dict-like representation.

The java/C-style loops are, I feel, your bottleneck here and you might want to switch to a more batch-style data processing. Look into Pandas as a potential data structure for this instead. Particularly, the “apply” method will be of interest to you. Alternatively, if you can handle this data processing in the backend, that would be even more preferable since databases are built for exactly this purpose.

1 Like

Thanks for the feedback. Ill look into pandas apply first.