Datatable show tooltip only on certain columns

Hi, this may be more of a question that’s related to programming in Python, but I’m trying to make it so that the tooltip is only visible on certain columns. Currently I have got it to show on all columns with the following code:

tooltip_data = [
        {
            column: {'value': str(value), 'type': 'markdown'}      
            for column, value in row.items()
        } for row in df.to_dict('records')
    ]

I’m thinking that I would need an if-statenebt, such as if column == 'column1' && column == 'column2' to make the tooltip to show on certain columns, but not sure where to add. Thanks!

Hi,

You can add it in the row iterator, like this:

tooltip_data = [
        {
            column: {'value': str(value), 'type': 'markdown'}      
            for column, value in row.items() if column in ["column1", "column2"]
        } for row in df.to_dict('records')
]

Hope this helps!

1 Like