table 列的 R 闪亮鼠标悬停文本
R shiny mouseover text for table columns
如何在 R 闪亮数据 table 显示中为列名创建 mouseover text
。
我试图为用户提供一些文本来理解列名。
我也检查了 DT 包,但找不到解决方案。
我可以为列名创建标签,并在用户选中一个框时显示所有标签,这会占用大量空间,我不希望这样。
有什么建议吗?
您可以在 Shiny 的 renderDataTable()
函数中使用 options
来实现。在 Shiny 的 DT 的 documentation 页面上,类似这样的东西应该可以工作。
renderDataTable(head(iris, 20), options = list(
initComplete = JS(
"function(settings, json) {",
"$(this.api().table().header()).on({
mouseenter: function () {
//stuff to do on mouse enter
},
mouseleave: function () {
//stuff to do on mouse leave
}
});",
"}")
))
为了扩展我上面的评论,这里有一个例子显示了我使用 title
属性的意思:
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
属性的另一种方法:
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 闪亮数据 table 显示中为列名创建 mouseover text
。
我试图为用户提供一些文本来理解列名。
我也检查了 DT 包,但找不到解决方案。
我可以为列名创建标签,并在用户选中一个框时显示所有标签,这会占用大量空间,我不希望这样。
有什么建议吗?
您可以在 Shiny 的 renderDataTable()
函数中使用 options
来实现。在 Shiny 的 DT 的 documentation 页面上,类似这样的东西应该可以工作。
renderDataTable(head(iris, 20), options = list(
initComplete = JS(
"function(settings, json) {",
"$(this.api().table().header()).on({
mouseenter: function () {
//stuff to do on mouse enter
},
mouseleave: function () {
//stuff to do on mouse leave
}
});",
"}")
))
为了扩展我上面的评论,这里有一个例子显示了我使用 title
属性的意思:
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
属性的另一种方法:
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]);
}
"))