Skip to content
This repository was archived by the owner on Aug 29, 2025. It is now read-only.
This repository was archived by the owner on Aug 29, 2025. It is now read-only.

Additional Built-in Conditional Formatting Formulas #767

Open

Description

@chriddyp

In DataTable's conditional formatting, we currently embed computed values into filter queries. For example, to highlight the maximum value of a column, we might write:

dash_table.DataTable(
    style_data_conditional=[
        {
            'if': {
                'column_id': 'Pressure',

                # since using .format, escape { with {{
                'filter_query': '{{Pressure}} = {}'.format(df['Pressure'].max())
            },
            'backgroundColor': '#85144b',
            'color': 'white'
        },
    ]
)

While this works great most of the time, there are two shortcomings to this approach:

  1. The syntax or computations can be tedious or difficult for certain computations, like highlighting the top 2 values in every row.
  2. If the table is editable, then the computed values may not be accurate anymore. For example, if a user enters a value into the table that is greater than the current maximum.

#1 can be solved via documentation and #2 can be worked around by updating style_data_conditional via a callback when derived_virtual_data changes.

In the future, it may be nice to provide these filter expressions built-in to the table. We currently document workarounds for:

  • max, min, average (per column, per table, and per row)
  • top N and bottom N (per column, per table, and per row)
  • Above average or below average (per column, per table, and per row)
  • Heatmap gradients (per column, per table, and per row)
  • Top N% or bottom N% (per column, per table, and per row)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions