Callbacks for elements generated via iterations


I’m generating cards kind of UI using dash html via iterations. The card count and its contents are dynamically generated based on the data. Each card is clickable. What would be feasible and right way to implement callbacks for click events on cards ?

Does Dash provides a way to use wildcard / regex as element identifiers for callbacks ?

cards_html = []
for card in cards:
cards_html.append(make_card_element(card)) # generates card

In this case, how to write callbacks for card clicks where the clicked card can be identified in callback.

We’ve discussed this but haven’t implemented it yet

Until then I think you have to pre-generate all the callbacks you might ever need. Not the nicest, and there are some cases we know this can’t cover…

Thanks for the response @alexcjohnson.

As you said, there are options for making it work like pre-generating callbacks using a range. If so, is there any restriction / drawback related with number of callbacks in dash ?

Let say, in my case, the cards count won’t exceed 20, i would be pre-generating 20 callbacks.

At some point you’d notice a performance cost, though in the tens of callbacks you should be fine.

If the callback for a card has all its inputs and outputs on that same card, this strategy works. The challenge is if you wanted the cards to interact with things outside of the cards - then you have an item that always exists depending on items that may or may not exist, and that’s not something we support right now.