Can we update dbc.card elements in group or via dictionary

I am updating a single card using a callback routine ;
I have around 10 elements to update.
As per my practice, I can write a routine that will pass these 10 elements to update.

But,
Is it possible in the dash to update all the elements of the card by passing a dictionary? ( i.e in a group )

@yogi_dhiman,

Do you have a snippet of your callback function?

It doesnt look like it would be possible since it isnt props, however, you could create a function where you pass a dictionary and it responds back with a fully created card.

Jinnyzor that is what I am doing I have a dictionary that is passed to the function that is creating the card.

So, for simplicity let’s say we have a card element as follows in the Card body

def create_card(card_description):
my_card = dbc.Card(
[
dbc.CardBody([
dbc.Row(
[
dbc.Col(html.Div(“COMPANY NAME”), width=6),
dbc.Col(dbc.Input(placeholder=“your company name”, type=“text”,disabled = True,id = ‘company_name’), width=6),
],style = {‘margin-left’ : ‘5px’,‘margin-right’ : ‘5px’,‘margin-top’ : ‘5px’,‘margin-bottom’ : ‘5px’}
)
])
return my_card

card_description is the dictionary that contains the company name.

How will I feed values in my_card ids? Also please suggest how an I change the style color of the card base on value (green for +1 and red for -1 ) in one of dictionary element.

Hi @yogi_dhiman ,

I am not sure what the actual question is.

Concerning ID’s and color: why don’t you include a ID for each comany in your dictionary, as well as the color?

dbc.Card(id=card_description['id'], children=..., color=card_description['color'])

@yogi_dhiman,

Here is an small example, you can expand the dictionary to include whatever properties you want to feed.

def buildCard(cd):
      if cd['color'] == '+1':
          color = 'green'
      elif cd['color'] == '-1':
          color = 'red'
      else:
          color = 'black'

      myCardDetails = #the predefined format you want for the card from the dictionary, ie. values, colors, other styles.

      myCard = dbc.Card(id=cd['id'], children=myCardDetails)
      return myCard

myCards = [{'id':'card1', 'description':'this is a test'},{'id':'card2'},{'id':'card3'}]

layout = []

for cd in myCards:
     layout.append(myCard(cd))

You can use this to dynamically update a single id or redo all the cards in a single callback depending on what triggered the changes.