Python/Dash - How to use f strings in filter query while doing conditional formatting in plotly Dash

I have a style_conditional list in Dash_Datatable

my_value_1 = 'Fruits'
        style_data_conditional = 
      # Colour red when values are less
          'if': {
                 'column_id': str(column), 
             'filter_query': f'{{{my_value_1}}} eq "Apples" && {{{column}}} > {{{benchmark}}} +10 or {{{column}}} < {{{benchmark}}} +10 ' },
          'backgroundColor': 'red',
                    'color': 'white'
        } for column in data.iloc[:,1:].columns 

If I remove the +10 part in the inequalities then it’s working but the logic of the problem demands that there be +10 in both inequalities. benchmark is the value of a dropdown the options being the columns after the first one as evident from the loop I’ll require help with this f string.

Here’s an example breaking down how this works with format in the docs. Might be helpful?

1 Like

Hi, thanks for your reply and awesome explanation!
I can make it work with {{{column}}} < {{{benchmark}}} but not being able to make it work when the inequality is basically column < benchmark + 10.
Any input is highly appreciated.

What about adding a new (hidden) column with the desired metric (i.e. benchmark +10)?

Can you help me with the syntax?