How to get conditional tooltip to appear only on matching cells of datatable

I have a dataTable with string values and I want to show a tooltip only for individual cells with certain values (in this case cells with a value of ‘***’). I assumed that something like this would work:

tooltip_conditional=[
    {
        'if': {
            'column_id': col,
            'filter_query': '{{{col}}} = "***"',
        },
        'type': 'markdown',
        'value': 'This column is significant.'
    } for col in data.columns
]

But it does not. If I take out the ‘filter_query’ line, it shows the tooltip on all rows and columns, but I cannot get it to limit the display to a specific value. I’ve tried different filter_query formulas (‘==’, ‘contains’, ‘in’, etc.) and nothing works.

Is this possible with tooltip_conditional?

Hi @etonblue

 'filter_query': f'{{{col}}} ={"***"}',

Here’s a full example:



from dash import Dash, dash_table
import pandas as pd
from collections import OrderedDict

data = OrderedDict(
    [
        ("Date", ["2015-01-01", "2015-10-24", "2016-05-10", "2017-01-10", "2018-05-10", "2018-08-15"]),
        ("Region", ["Montreal", "Toronto", "New York City", "Miami", "San Francisco", "London"]),
        ("Temperature", [1, -20, 3.512, 4, 10423, -441.2]),
        ("Humidity", [10, 20, 30, 40, 50, 60]),
        ("Pressure", [2, 10924, 3912, -10, 3591.2, 15]),
    ]
)
df = pd.DataFrame(data)

app = Dash(__name__)

app.layout = dash_table.DataTable(
    data=df.to_dict('records'),
    columns=[{'name': i, 'id': i} for i in df.columns],

    tooltip_conditional=[
        {
            'if': {
                'filter_query': f'{{{col}}} = {"Montreal"}',
                'column_id': col
            },
            'type': 'markdown',
            'value': 'This row is significant.'
        } for col in df.columns
    ],
    tooltip_delay=0,
    tooltip_duration=None
)


if __name__ == '__main__':
    app.run_server(debug=True)



1 Like

Arg. I was so close. Thanks!

1 Like