2017-07-11 21 views
0

我想要创建一个闪亮的数据表,突出显示用户的鼠标正在徘徊的单元格,方式是突出显示同一行和列中的单元格。它与此处显示的内容类似: https://datatables.net/examples/api/highlight.html突出显示单元格在鼠标悬停在有光泽的数据表上的位置

但在此示例中,整列将突出显示,并且我希望它停在鼠标所在的单元格上。

我已经看到类似问题的其他问题,例如:R shiny mouseover text for table columns。但我不知道它是否过时,但该代码不适用于我,它只是显示一个正常的数据表。

以下面的代码为例,我该如何做到这一点?

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() 
        ) 
    ) 

    }) 
    } 
) 

回答

1

我知道如何突出一排悬停

#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)) 

enter image description here

+0

也就是说很接近,如果不出意外显示了,我会接受你的答案。 –

相关问题