# Dash DataTable - Tooltips

**URL:** <https://community.plotly.com/t/dash-datatable-tooltips/6327>\
**Category:** Dash Python\
**Created:** [October 17, 2017, 6:46am UTC](https://community.plotly.com/t/dash-datatable-tooltips/6327 "2017-10-17T06:46:36Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![HansG](https://avatars.discourse-cdn.com/v4/letter/h/958977/32.png) [@HansG](https://community.plotly.com/u/HansG)\
**Post date:** [October 17, 2017, 6:46am UTC](https://community.plotly.com/t/dash-datatable-tooltips/6327/1 "2017-10-17T06:46:36Z")

</div>

Hey,  
Is it possible to add a custom tooltip to a cell or headline of the DataTable?

---

<div class="post-metadata">

**Author:** ![chriddyp](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/chriddyp/32/16855_2.png) [@chriddyp](https://community.plotly.com/u/chriddyp)\
**Post date:** [October 17, 2017, 4:56pm UTC](https://community.plotly.com/t/dash-datatable-tooltips/6327/2 "2017-10-17T16:56:28Z")

</div>

This isn’t possible now. I’d like to make formatting more generic across Dash by allowing you to pass in components inside properties besides `children`. This would allow you to pass in dash components as header cells, one of which could be a tooltip. Here’s the PR: [https://github.com/plotly/dash-table-experiments/pull/11](https://github.com/plotly/dash-table-experiments/pull/11). There is still quite a bit of work to do here.

---

<div class="post-metadata">

**Author:** ![chriddyp](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/chriddyp/32/16855_2.png) [@chriddyp](https://community.plotly.com/u/chriddyp)\
**Post date:** [February 25, 2019, 9:21pm UTC](https://community.plotly.com/t/dash-datatable-tooltips/6327/3 "2019-02-25T21:21:28Z")

</div>

Thanks to our commercial customers, this is now available in dash-table ([https://dash.plot.ly/datatable](https://dash.plot.ly/datatable)).

 ![tooltip](https://us1.discourse-cdn.com/flex024/uploads/plot/original/2X/a/ac7d54cce7ebd78738388980a60ee76205621a4e.gif)

```auto
import dash
import dash_core_components as dcc
import dash_html_components as html
import dash_table as table

import pandas as pd
import textwrap

df = pd.read_csv('./datasets/gapminder.csv')

print(dash. __version__ )
print(table. __version__ )

app = dash.Dash( __name__ )
app.scripts.config.serve_locally = True
app.css.config.serve_locally = True

def create_tooltip(cell):
    try:
        num = float(cell)
        return textwrap.dedent(
            '''
            Tooltip for value **{value:+.2f}**.
            | Multiplier | Value | Percent |
            |-------|-------|---------------|
            | 1 | {value_1:+.2f} | {value_1:+.2f}% |
            | 2 | {value_2:+.2f} | {value_2:+.2f}% |
            | 3 | {value_3:+.2f} | {value_3:+.2f}% |
            '''.format(
                value=num,
                value_1=num,
                value_2=num * 2,
                value_3=num * 3
            )
        )
    except:
        return textwrap.dedent(
            '''
            Tooltip: **{value}**.
            '''.format(value=cell)
        )

app.layout = html.Div([
    table.DataTable(
        columns = [{'name': i, 'id': i} for i in df.columns],
        data=df.to_dict('rows'),
        tooltips={
            col: [
                {
                    'type': 'markdown',
                    'value': create_tooltip(df.loc[i, col])
                }
                for i in range(len(df))
            ]
            for col in df.columns
        }
    )
])

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

```

---

<div class="post-metadata">

**Author:** ![gnigg](https://avatars.discourse-cdn.com/v4/letter/g/c4cdca/32.png) [@gnigg](https://community.plotly.com/u/gnigg)\
**Post date:** [March 2, 2019, 4:40pm UTC](https://community.plotly.com/t/dash-datatable-tooltips/6327/4 "2019-03-02T16:40:41Z")

</div>

Coincidentally, I was looking into this just days ago. Upgraded data\_table and voila, everything worked as described. Thank you @chriddyp for Dash and everything that comes with it (like these DataTable tooltips)!!!

---

<div class="post-metadata">

**Author:** ![stathis](https://avatars.discourse-cdn.com/v4/letter/s/e79b87/32.png) [@stathis](https://community.plotly.com/u/stathis)\
**Post date:** [May 23, 2019, 12:29pm UTC](https://community.plotly.com/t/dash-datatable-tooltips/6327/5 "2019-05-23T12:29:36Z")

</div>

Hi - extremely handy feature. Is there any way to have conditional tooltips only for the headers?

When I try something like the below, it starts counting from the first data row (which is fair choice, but how can I hit the header instead?):

```
column_conditional_tooltips=[
            {
                'if': {'column_id': "id1", "row_index": 0},
                "value": "My tooltip",
                "type": "text"
            },
        ]
```

---

<div class="post-metadata">

**Author:** ![rafaelc](https://avatars.discourse-cdn.com/v4/letter/r/9e8a1a/32.png) [@rafaelc](https://community.plotly.com/u/rafaelc)\
**Post date:** [May 30, 2019, 2:43pm UTC](https://community.plotly.com/t/dash-datatable-tooltips/6327/6 "2019-05-30T14:43:41Z")

</div>

+1 on this, this would be really useful to explain what the columns are.

---

<div class="post-metadata">

**Author:** ![spencerlawrence](https://avatars.discourse-cdn.com/v4/letter/s/b3f665/32.png) [@spencerlawrence](https://community.plotly.com/u/spencerlawrence)\
**Post date:** [July 24, 2019, 7:59pm UTC](https://community.plotly.com/t/dash-datatable-tooltips/6327/7 "2019-07-24T19:59:16Z")

</div>

Hey @chriddyp, thanks for implementing this. Do you have a more recent example? Seems like tooltip has taken the place of tooltips, and I’m having trouble getting a test example with your code.

Here is a stripped-down version that is not working for me:

```
tooltip={
    'property':'my_column_name',
    'value':'this is a test tooltip' 
}
```

---

<div class="post-metadata">

**Author:** ![Motta23](https://avatars.discourse-cdn.com/v4/letter/m/b3f665/32.png) [@Motta23](https://community.plotly.com/u/Motta23)\
**Post date:** [August 5, 2019, 11:35am UTC](https://community.plotly.com/t/dash-datatable-tooltips/6327/8 "2019-08-05T11:35:12Z")

</div>

I also have this problem. Installing dash 0.39 and running the example with ‘tooltips’ works as expected. However, the latest version of Dash doesn’t render any tooltip by using either ‘tooltip’ or ‘tooltip\_data’. Anyone figured it out using dash \> 1.0.0?

---

<div class="post-metadata">

**Author:** ![titi31](https://avatars.discourse-cdn.com/v4/letter/t/ee59a6/32.png) [@titi31](https://community.plotly.com/u/titi31)\
**Post date:** [August 21, 2019, 9:01am UTC](https://community.plotly.com/t/dash-datatable-tooltips/6327/9 "2019-08-21T09:01:33Z")

</div>

> [@Motta23](#):
>
> I also have this problem. Installing dash 0.39 and running the example with ‘tooltips’ works as expected. However, the latest version of Dash doesn’t render any tooltip by using either ‘tooltip’ or ‘tooltip\_data’. Anyone figured it out using dash \> 1.0.0?

Hi! According to the documentation, you can make it work like this :

> [@](#):
>
> tooltip\_data=[{‘my\_column\_name’: ‘this is a test tooltip’ }]

Please note however that it will work only for the first row, you need to iterate if you want specific value on the rest of the column.

Otherwise, you can use the tooltip argument:

> [@](#):
>
> tooltip={‘my\_column\_name’: ‘this is a test tooltip’ }

---

<div class="post-metadata">

**Author:** ![Motta23](https://avatars.discourse-cdn.com/v4/letter/m/b3f665/32.png) [@Motta23](https://community.plotly.com/u/Motta23)\
**Post date:** [August 22, 2019, 9:34am UTC](https://community.plotly.com/t/dash-datatable-tooltips/6327/10 "2019-08-22T09:34:35Z")

</div>

Many thanks Titi! Works like a charm.

---

<div class="post-metadata">

**Author:** ![wvw](https://avatars.discourse-cdn.com/v4/letter/w/c68b51/32.png) [@wvw](https://community.plotly.com/u/wvw)\
**Post date:** [February 11, 2020, 3:18pm UTC](https://community.plotly.com/t/dash-datatable-tooltips/6327/11 "2020-02-11T15:18:42Z")

</div>

This is not working for me for tooltip. tooltip\_data does work Using dash 1.8.0. Anyone have a working example for multiple columns? I must add I’m looking for the tooltip in the column headings. This tooltip does work the data cell, but I’m using tooltip\_data for that.

---

<div class="post-metadata">

**Author:** ![tbillah](https://avatars.discourse-cdn.com/v4/letter/t/d6d6ee/32.png) [@tbillah](https://community.plotly.com/u/tbillah)\
**Post date:** [April 7, 2020, 4:21am UTC](https://community.plotly.com/t/dash-datatable-tooltips/6327/12 "2020-04-07T04:21:19Z")

</div>

Hello @chriddyp,

I modified your suggestions to work on dash 1.9.1 for my use case:

```python
tooltip_data= {c:
        [{
            'type': 'text',
            'value': f'{r},{c}'
        } for r in df[df.columns[0]].values]
     for c in df.columns
}

```

As you can probably see, I am trying to display my row,column names as the tooltips for all elements in the table. However, I get the following error on my web browser:

 ![tooltip_error](https://us1.discourse-cdn.com/flex024/uploads/plot/original/2X/5/54e05bc92bb72c81f6dc2d5e1fa5c4dae0af291d.png)

Can you help please?

---

<div class="post-metadata">

**Author:** ![tbillah](https://avatars.discourse-cdn.com/v4/letter/t/d6d6ee/32.png) [@tbillah](https://community.plotly.com/u/tbillah)\
**Post date:** [April 7, 2020, 4:23am UTC](https://community.plotly.com/t/dash-datatable-tooltips/6327/13 "2020-04-07T04:23:59Z")

</div>

Hi @wvw, have you found a way around yet?

---

<div class="post-metadata">

**Author:** ![chriddyp](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/chriddyp/32/16855_2.png) [@chriddyp](https://community.plotly.com/u/chriddyp)\
**Post date:** [April 7, 2020, 5:03am UTC](https://community.plotly.com/t/dash-datatable-tooltips/6327/14 "2020-04-07T05:03:19Z")

</div>

@tbillah - The error message looks like it’s telling you that the shape of the data you are passing isn’t right. It’s expecting an array, you passed a dict (object). Try

```auto
tooltip_data = [
    {'type': 'text', 'value': f{r},{c}' for r in df[df.columns[0]].values]} 
    for c in df.columns
] 

```

Do you have any suggestions on how we could make that error message clearer?

---

<div class="post-metadata">

**Author:** ![tbillah](https://avatars.discourse-cdn.com/v4/letter/t/d6d6ee/32.png) [@tbillah](https://community.plotly.com/u/tbillah)\
**Post date:** [April 7, 2020, 5:10am UTC](https://community.plotly.com/t/dash-datatable-tooltips/6327/15 "2020-04-07T05:10:33Z")

</div>

Hi @chriddyp, I think the error message is okay. Perhaps I should have mentioned, I also tried with square brackets around learning from the error. However, I tried again with what you provided and ran into the following:

 ![image](https://us1.discourse-cdn.com/flex024/uploads/plot/original/2X/0/06f2e845ec13b7662f3ef4455b4d3fb58dc19875.png)

By the way, I had to adjust your suggestion by inserting one missing square bracket:

```python
        tooltip_data = [
            {'type': 'text', 'value': [f'{r},{c}' for r in df[df.columns[0]].values]}
            for c in df.columns
        ]

```

---

<div class="post-metadata">

**Author:** ![tbillah](https://avatars.discourse-cdn.com/v4/letter/t/d6d6ee/32.png) [@tbillah](https://community.plotly.com/u/tbillah)\
**Post date:** [April 7, 2020, 1:42pm UTC](https://community.plotly.com/t/dash-datatable-tooltips/6327/16 "2020-04-07T13:42:51Z")

</div>

Hi @chriddyp, here is a better example:

> [@Datatable \`tooltip\_data\` argument - request for example](https://community.plotly.com/t/datatable-tooltip-data-argument-request-for-example/36276):
>
> hi i’ve tried all possible combinations i could think fo but can’t figure out what tooltip\_data wants passed to it structure-wise, there’s nothing in reference that clears this up. could someone please post an example of the structure for generating tooltip\_data structure for multirow multicol table please. which level is the outermost - row or col?, do you need to have a dict attached to each col key, is outermost structure list…? thigns to be grouped by row in lists…?

It appears that I had to interchange row and column order:

```python
tooltip_data= [{c:
        {
            'type': 'text',
            'value': f'{r},{c}'
        } for c in df.columns
} for r in df[df.columns[0]].values]

```

I realized that `tooltip_data` expects a list of dictionaries where each item in the dictionary is another dictionary for each column.

---

<div class="post-metadata">

**Author:** ![bajaj454](https://avatars.discourse-cdn.com/v4/letter/b/9de053/32.png) [@bajaj454](https://community.plotly.com/u/bajaj454)\
**Post date:** [July 31, 2020, 5:52pm UTC](https://community.plotly.com/t/dash-datatable-tooltips/6327/17 "2020-07-31T17:52:18Z")

</div>

Hello @chriddyp,  
Here is my code, I am trying to read a pandas data frame and upload it into dash data table.  
I tried to use the Ellipses and Tooltip functionality but somehow tooltip is not working for me.  
Please help me in running this (Variable Table is a pandas data frame)

import dash  
import dash.dependencies as dd  
import dash\_core\_components as dcc  
import dash\_html\_components as html  
from dash.dependencies import Input, Output, State  
import dash\_bootstrap\_components as dbc  
import dash\_table  
import pandas as pd

from navbar import Navbar  
nav = Navbar()  
from app import app

import fig\_prep\_code

df = pd.DataFrame()

output = dbc.Container(children =[  
dbc.Row([  
dbc.Col(html.H3(“User Emails”),width=10),  
dbc.Col(dbc.Button(“Click Me”,id=‘Emails\_submit’,outline=True, color=“dark”),align = ‘right’)  
],align = ‘center’),  
html.Hr(),  
dash\_table.DataTable(  
id=‘table’,  
columns = [{‘name’: i, ‘id’: i} for i in df.columns],  
data=df.to\_dict(‘records’),  
page\_size=20,  
style\_cell={  
‘overflow’: ‘hidden’,  
‘textOverflow’: ‘ellipsis’,  
‘textAlign’: ‘left’,  
‘maxWidth’: ‘0’,  
},

```
    tooltip_data=[{
            column: {'value': str(value), 'type': 'markdown'}
            for column, value in row.items()
        } for row in df.to_dict('rows')
    ],
    tooltip_duration=None,
    fixed_rows={'headers': True}

)

```

])

def MAILS():  
layout = html.Div([nav,output])  
return layout

@app.callback([Output(‘table’, ‘data’),  
Output(‘table’, ‘columns’),  
Output(‘table’, ‘rows’)],  
[  
Input(‘Emails\_submit’, ‘n\_clicks’)],  
[  
State(‘select\_all’, ‘value’),  
State(‘folder\_picker’, ‘value’),  
State(‘employee\_picker’, ‘value’),  
State(‘search\_string’, ‘value’),  
State(‘search\_options’, ‘value’),  
State(‘NSFW’, ‘value’),  
State(‘Money’, ‘value’),  
State(‘Order’, ‘value’),  
State(‘outside\_from’, ‘value’),  
State(‘outside\_to’, ‘value’),  
State(‘group\_mail’, ‘value’),  
State(‘flag\_condition’, ‘value’),  
State(‘Sentiment’, ‘value’),  
State(‘date\_picker’, ‘start\_date’),  
State(‘date\_picker’, ‘end\_date’)  
])  
def update\_figure\_mail(n\_clicks,select\_all,folder,selected\_employee,search\_keyword,search\_options,NSFW,Money,Order,outside\_from,outside\_to,group\_mail,flag\_condition,Sentiment,start\_date, end\_date):  
Table, Year, DOW, Hour,To, Folder,number\_emails,chart\_from = fig\_prep\_code.graph(select\_all,folder,selected\_employee,search\_keyword,search\_options,NSFW,Money,Order,outside\_from,outside\_to,group\_mail,flag\_condition,Sentiment,start\_date, end\_date)

```
Table['Comments'] = ''
df = Table

return Table.to_dict('records'), [{"name": i, "id": i} for i in Table.columns], Table.to_dict('rows')
```

---

<div class="post-metadata">

**Author:** ![matt\_haugh](https://avatars.discourse-cdn.com/v4/letter/m/74df32/32.png) [@matt\_haugh](https://community.plotly.com/u/matt_haugh)\
**Post date:** [October 28, 2020, 7:14pm UTC](https://community.plotly.com/t/dash-datatable-tooltips/6327/18 "2020-10-28T19:14:05Z")

</div>

You can do this using dash bootstrap components [tooltips](https://dash-bootstrap-components.opensource.faculty.ai/docs/components/tooltip/).

The syntax for the tooltip component looks like this:

```auto
dbc.Tooltip(
    "Noun: rare, "
    "the action or habit of estimating something as worthless.",
    target="tooltip-target",
),

```

To get this tooltip to pop up over the header of a specific column, you need it’s class id and the table id (otherwise the tooltip will potentially appear over every table in your app). The class id can be found using your browsers developer tools to inspect the dashboard elements. So for the 2nd column in a table with an id of “test-table” the tooltip component should look like this:

```auto
dbc.Tooltip(
    "Test tooltip",
    target="test-table th.dash-header.column-1",
),

```
