表格列的R闪亮鼠标悬停文字 [英] R shiny mouseover text for table columns

查看:71
本文介绍了表格列的R闪亮鼠标悬停文字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何为R闪亮数据表显示中的列名称创建鼠标悬停文本
我正在尝试提供一些文本供用户理解列名。
我也签到了DT包裹,但找不到解决方案。
我可以为列名创建标签,并在用户选中一个框时显示所有标签,这会占用很多空间,我不希望这样。
有什么提示吗?

How can I create mouseover text for column names in R shiny data table display. I'm trying to provide some text for users to understand the column names. I checked in DT package also and I couldn't find a solution. I can create labels for column names and display all of them when a user checks a box, this takes a lot of real estate and I don't want that. Any tips?

推荐答案

为在上面扩展我的评论,下面的示例显示了我使用 title 属性:

To expand my comment above, here is an example showing what I meant by using the title attributes:

library(DT)
sketch = htmltools::withTags(table(
  class = 'display',
  thead(
    tr(
      th('', title = 'Row Names'),
      th('Sepal.Length', title = 'The Sepal Length'),
      th('Sepal.Width', title = 'The Sepal Width'),
      th('Petal.Length', title = 'The Petal Length'),
      th('Petal.Width', title = 'The Petal Width'),
      th('Species', title = 'Iris Species')
    )
  )
))
datatable(iris, container = sketch)

这是使用JavaScript(jQuery)添加 title 属性的另一种方法:

And here is another approach using JavaScript (jQuery) to add the title attributes:

library(DT)
datatable(iris, callback = JS("
var tips = ['Row Names', 'The Sepal Length', 'The Sepal Width',
            'The Petal Length', 'The Petal Width'],
    header = table.columns().header();
for (var i = 0; i < tips.length; i++) {
  $(header[i]).attr('title', tips[i]);
}
"))

这篇关于表格列的R闪亮鼠标悬停文字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆