R shiny mouseover text for table columns

前端 未结 2 2143
时光取名叫无心
时光取名叫无心 2020-12-05 03:47

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 c

2条回答
  •  醉酒成梦
    2020-12-05 04:11

    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)
    

    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]);
    }
    "))
    

提交回复
热议问题