I am trying to achieve something that I thought would be straight-forward for Dash datatable, but it appears it's a little bit more complicated than I initially assumed.
I have a datatable with 10 columns whose values are all numeric, and whose names are timestamps in string format - as such, these names change over time (and thus I can't perform conditional formatting using hard-coded column names for the 'style_data_conditional' parameter of my Dash datatable).
As a result, I need a dynamic way of specifying that each cell for each one of these columns appears in red font for negative values and in green for positive values.
I thought I could use dictionary comprehension to generate a dynamically created list of conditional formatting rules - this code is syntactically incorrect but it should demonstrate what I am trying to achieve:
style_data_conditional = ([
{
'if': {
'column_id': fieldname,
'filter_query': '{' + field_name + '} > 0'
},
'color': 'green'
} for field_name in data_table.columns,
{
'if': {
'column_id': fieldname,
'filter_query': field_name + ' < 0'
},
'color': 'red'
} for field_name in data_table.columns,
])
Would anyone have an idea of another approach that could be taken to solve this problem?
Thanks,