question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Tooltip Not Working on Dash/Datatable update

See original GitHub issue

Following the Dash Experiment (https://community.plot.ly/t/dash-datatable-tooltips/6327/3) the tooltip works on Dash version 0.39 (Datatable version 3.6.0), but not on 1.0.0+ (Datatable version 4.1.0).

I know that the naming of ‘tooltips’ has been changed in version 1.0.0 (although it’s not very clear whether it should be ‘tooltip’ or ‘tooltip_data’), but both of these don’t seem to work:

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('https://raw.githubusercontent.com/plotly/datasets/master/gapminderDataFiveYear.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'),
        tooltip={
            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)

I’ve tested the code above (with the term ‘tooltips’ instead of ‘tooltip’) on Dash 0.39 (Datatable version 3.6.0) and it works fine. It doesn’t however on the new version. Reading through the docs, the only change has been on the term ‘tooltips’. Unless I’m doing something horribly wrong, I think this is a bug.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:10

github_iconTop GitHub Comments

6reactions
happyshowscommented, Sep 6, 2019

k finally I got it, you need to wrap the row loop outside of the column id loop (not inside)

tooltip_data=[{
                col: f"{col} {i} th row"
                for col in _df.columns} for i in range(0,_df.shape[0])],
1reaction
ybresslercommented, Apr 1, 2020

@vlemmy I’m having similar issues…

The issue is an ambiguity in the documentation’s requirements for providing tooltip_data. Perhaps borrowing from syntax of another programming language, the format is as follows:

  • tooltip_data: a list of dictionaries (one for each row) >>
    • keys = column name(s)
    • value:
      • a string for the value to be shown on hover
      • a dictionary:
        • keys = "value", "type", "duration" etc. (according to documentation)
        • values = corresponding values as documented.

As you can see, the overlapping language creates room for error. Also, you have to operate rowwise – which isn’t intuitive.

Here’s an example (in long form):

# an empty list for now
tooltip_data = []

# operate rowwise
for i in range(0,df.shape[0]):
    # each row needs a dictionary
    t_row = {}

    for col in ["col_1", "col_2"]: 
        if col in df.columns:
            # add to the row dict
            x = df[col][i]
            t_row[col] = x
            # Alternatively, the following format would work
            # t_row[col] = {"value" : x }

        # don't include empty rows
        if len(t_row)>0:
            tooltip_data.append(t_row)

Oh, and tooltip_data = tooltip_data should be used in the latest version of plotly.

Hope this solves it for you!

Read more comments on GitHub >

github_iconTop Results From Across the Web

DataTable Tooltips | Dash for Python Documentation | Plotly
DataTable Tooltips allow you to provide additional information about table cells or headers when hovering your mouse over cells.
Read more >
Creating tooltip using callback for dash DataTable
Results in a syntax error as tooltip is not defined. The callback configuration will specify where the callback return value(s) go. In this...
Read more >
Tooltip - Dash Plotly DataTable - YouTube
Learn how to add the tooltip to the Dash DataTable to make your dashboard app more informative and user-friendly.
Read more >
Tooltip - dbc docs - Dash Bootstrap Components - Faculty AI
To use the Tooltip component, simply add it to the layout of your app, and give it the id of a component in...
Read more >
dccTooltip: Tooltip component in plotly/dashR - Rdrr.io
In plotly/dashR: An Interface to the Dash Ecosystem for Authoring Reactive Web ... optional): determines if the component is loading or not ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found