简体   繁体   中英

Conditional Styling with Dash Bootstrap with IF statement

I'm trying to apply two different colors based on the text value in the column by using Dash bootstrap and some of the HTML components. For example, the table looks like this.

Value

Yes
No
Yes
Yes
No

I want to change the color of the text to green if it's "Yes and to red if it's "No". I tried the following lines but it seems like the if statement doesn't work in this way.

html.Td(
         a["Value"],
         if a["Value"] == "Yes":
              style={"color": "green"},
         else:
              style={"color": "red"},
                                       ) for a in i["Items"]

try Ternary Operators :

html.Td(a["Value"],
   style={"color": "green"} if a["Value"] == "Yes" else {"color": "red"})

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM