Black Lives Matter. Please consider donating to Black Girls Code today.

How to create multiple callbacks using a double for loop?

I have a scenario where I need to create multiple callbacks functions and there is a possibility to replicate that using double for loops but it doesn’t work. It seems to be working fine with a single for loop or without any, but with double for loops, the dash app doesn’t seem to create these callbacks.

for i in range(5):
for j in range(5):
@app.callback(Output(‘i-j’,‘children’),[Input(…)])
def foo(value):
pass

I want to know is that even possible to do so with Dash?
Best

From you code, it seems like you are assigning the string ‘i-j’ as id, not the values of i and j. To do the latter, it would be ‘{}-{}’.format(i,j).

I would also recommend checking out pattern matching callbacks for use cases like these: https://dash.plotly.com/pattern-matching-callbacks.