将鼠标悬停在列标题上以在破折号数据表中进行描述

问题描述

我能够使用tooltip_data悬停在某些单元格上并显示一些数据。

是否有针对标头的方法?因此,我可以对每列代表什么做一个简短描述?

在这里看了一下,但并没有真正回答是否可能。 https://community.plotly.com/t/dash-datatable-tooltips/6327/3

谢谢!

解决方法

您真幸运。这是一个非常需要的功能,并且最近已经实现。

records = {'col_1': [3,2,1,0],'col_2': ['a','b','c','d']}
df = pd.DataFrame.from_dict(records)

app.layout = dash_table.DataTable(
    data=df,columns=[{'id': c,'name': c} for c in df.columns],tooltip_header={
        'col_1': 'Column 1','col_2': 'Column 2',},# Overflow into ellipsis
    style_cell={
        'overflow': 'hidden','textOverflow': 'ellipsis','maxWidth': 0,tooltip_delay=0,tooltip_duration=None
)
,

您可以使用破折号引导程序组件tooltips来做到这一点。

工具提示组件的语法如下:

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

要使此工具提示弹出特定列的标题上方,您需要它的类ID和表ID(否则该工具提示可能会出现在应用程序的每个表中)。可以使用浏览器开发人员工具检查仪表板元素来找到类ID。因此,对于ID为“ test-table”的表中的第二列,工具提示组件应如下所示:

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