How to grab value of cell during conditional formatting?

Hey! I’m trying to grab the value of the cell during conditional formatting of a dash data table, is this possible? Looking to set the alpha of a cell based on its value without having a rule for each integer.

In this example:

 dash_table.DataTable(
    data=df.to_dict('records'),
    columns=[
        {'name': i, 'id': i} for i in df.columns
    ],
    style_data_conditional=[
        {
            'if': {
                'column_id': 'Region',
                'filter_query': '{Region} eq "Montreal"'
            },
            'backgroundColor': '#3D9970',
            'color': 'white',
        },
        {
            'if': {
                'column_id': 'Humidity',
                'filter_query': '{Humidity} eq 20'
            },
            'backgroundColor': '#3D9970',
            'color': 'white',
        },
        {
            'if': {
                'column_id': 'Temperature',
                'filter_query': '{Temperature} > 3.9'
            },
            'backgroundColor': '#3D9970',
            'color': 'white',
        },
    ]
)  

Is there a way get the {temperature}, pass it through a simple mathematical function and have the result be the background color?

Thanks!

@robswc Sadly there’s currently no way to natively use the value of a field in a formula to return a modified value to use on props. We are discussing the feasibility of adding formula support to the table but there’s no specific plans or timeline yet. Maybe it will look something like this:

{
  if: { column_id: 'temperature' },
  background_color: 'gradient(0, 100, {temperature}, blue, red)'
}

The best you can do for now with the props is define ranges with the appropriate colors and have each range represented by a conditional style. The more granular, the more gradient-like, but the more costly in terms of cpu / resources when rendering the table.

{
  if: { column_id: 'temperature', filter_query: '{temperature} ge 0 && {temperature} lt 10' },
  background_color: '#0000FF'
},
{
  if: { column_id: 'temperature', filter_query: '{temperature} ge 10 && {temperature} lt 20' },
  background_color: '#0000CC'
},
// ...

Related to Dash-table: Graded Color Scale (conditional formatting) slow

ah makes sense, I was wondering if I just wasn’t getting something… I did come across this in the mean time.

would it be possible using the .format() function perhaps? or would I be wasting my time going down that road?

Thanks!

Using .format() only allows you to apply certain values to a string template. It can be helpful when you have the same logic to apply over many columns / rows / etc. to build conditions / style /etc. but it not otherwise strictly related to the problem you are experiencing.

Hi! I was wondering if there was any update on this. Let’s say I have max_capacity and n_people columns. Can I multiply max_capacity by 0.9 and do a conditional format, so that n_people values that are above that threshold are painted red?

Thanks in advance!

Hello! I am following up to see if there was an update on this. I have a numeric column with mixed formats, dollars and percentages, and I would like to have anything >= 1 be formatted with dollars and anything < 1 be formatted as a percentage. Is there any way to access and format the value based on that logic?

Thanks for your time!!