【问题标题】:Hover over column header for description in dash datatable将鼠标悬停在列标题上以获取破折号数据表中的描述
【发布时间】:2020-12-02 11:21:39
【问题描述】:

我可以使用 tooltip_data 将鼠标悬停在一些单元格上并显示一些数据。

有没有办法为标题做到这一点?所以我可以添加每个列代表什么的简要说明?

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

谢谢!

【问题讨论】:

    标签: python plotly-dash


    【解决方案1】:

    您可以使用破折号引导组件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",
    ),
    

    【讨论】:

      【解决方案2】:

      你很幸运。这是一项要求很高的功能,最近已实施。

      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
      )
      

      【讨论】:

        猜你喜欢
        • 2017-03-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-10-18
        • 1970-01-01
        • 2014-03-09
        • 1970-01-01
        相关资源
        最近更新 更多