Conditional formatting of dbc.Table - red/green negative/positive values

Hello,

I am using dbc.Table to create a table in a web app, cause I like the flexibility, the look of it and the bootstrap style.

I would to apply a conditional formatting to the table, e.g. I would like to make green positive values and red the negative values, only to some of the columns.

I see I can do it in the datatable component, but I do not know how to do it for the dbc.Table.

Any Idea? thanks a lot for your help!!

Hi @Trydash2021,
Maybe you can use a if else condition to set the color and then apply it with style?
https://dash-bootstrap-components.opensource.faculty.ai/docs/components/table/

1 Like

Hi @jgomes_eu ,

thanks for your reply, I ended up doing something like you said, implementing some if condition while building up the dbc.table using for i loop over a dataframe. I post here an extract/exemple of the code, if this could be useful for somebody (i is a variable that I use to loop over the dataframe df to build the dbc.table) :

                html.Td(
                    html.P(i,
                        style={'color':'red'}
                        ) if (
                        isinstance(i, numpy.float64) and i<0
                        ) else (
                    html.P(i)
                        )
                    )
1 Like

Great example!