突出显示鼠标悬停在闪亮数据表中的单元格位置

Sol*_*aga 1 r shiny dt

我想创建一个闪亮的数据表,以突出显示用户鼠标悬停在其上的单元格,以突出显示同一行和同一列中的单元格。它类似于此处显示的内容:https : //datatables.net/examples/api/highlight.html

但是在这个例子中,整个列都被突出显示,我希望它停在鼠标所在的单元格上。

我见过其他有类似问题的问题,比如这个:R 表列的闪亮鼠标悬停文本。但我不知道它是否已经过时,但该代码对我不起作用,它只是显示一个普通的数据表。

以下面的代码为例,我怎样才能做到这一点?

library(shiny)

shinyApp(
  ui = fluidPage(
    DT::dataTableOutput("mtcarsTable")
  ),
  server = function(input, output) {

    output$mtcarsTable <- DT::renderDataTable({
      DT::datatable(datasets::mtcars[,1:3], 
                    options = list(rowCallback = JS()
                    )
      )

    })
  }
)
Run Code Online (Sandbox Code Playgroud)

Por*_*hop 5

我知道如何在悬停时突出显示一行

#rm(list = ls())
library(shiny)
library(DT)

ui <- basicPage(
  tags$style(HTML('table.dataTable.hover tbody tr:hover, table.dataTable.display tbody tr:hover {background-color: pink !important;}')),
  mainPanel(DT::dataTableOutput('mytable'))
)

server <- function(input, output,session) {

  output$mytable = DT::renderDataTable(    
    datatable(mtcars)
  ) 
}
runApp(list(ui = ui, server = server))
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明