有没有办法在r闪亮的数据表中获取每个单元格的工具提示?有很多方法可以获得悬停行或列。但我找不到一种方法来获取行和列索引,并为每个单元格显示不同的悬停工具提示。有人能修改以下代码吗?
library(shiny)
library(DT)
shinyApp(
ui = fluidPage(
dataTableOutput('table'),
verbatimTextOutput('hoverIndex'),
),
server = function(server, input, output) {
output$hoverIndex <- renderText({
UI_out <- input$hoverIndexJS
return(paste("hover column info", UI_out))
})
output$table <- renderDataTable({
DT_out <- data.frame(`A` = 1:5, `B` = 11:15, `C` = LETTERS[1:5])
DT_out <- datatable(DT_out
,rownames = F
,callback = JS("
/* code for columns on hover */
table.on('mouseenter', 'td', function() {
var td = $(this);
var col = table.cell( this ).index().columnVisible;
var row = table.cell( this ).index().row;
$('td[row][col]).attr('title', row+col);
Shiny.onInputChange('hoverIndexJS', info_out);
});"
)
)
return(DT_out)
})
}
)