gpt4 book ai didi

javascript - R Shiny : Mouse Hover Text for Datatable Rows

转载 作者:行者123 更新时间:2023-11-30 14:12:26 26 4
gpt4 key购买 nike

有没有办法在数据表显示中将鼠标悬停在一行(记录)上时显示鼠标悬停文本?在 StackOverflow 上浏览了一些类似的问题后,我找到了 2 个示例代码,一个显示列单元格的悬停文本,一个在鼠标悬停时突出显示整行。

显示列单元格悬停文本的示例代码:

library(shiny)
library(DT)

shinyApp(
ui = fluidPage(

DT::dataTableOutput("table2")

),
server = function(input, output) {

output$table2<-DT::renderDataTable({
responseDataFilter2_home<-iris[,c(4,3,1)]
displayableData<-DT::datatable(responseDataFilter2_home,options = list(rowCallback = JS(
"function(nRow, aData, iDisplayIndex, iDisplayIndexFull) {",
"var full_text = aData[1] + ','+ aData[2]",
"$('td:eq(1)', nRow).attr('title', full_text);",
"}")
))#, stringAsFactors = FALSe, row.names = NULL)
},server = TRUE, selection = 'single', escape=FALSE,options=list(paging=FALSE,searching = FALSE,ordering=FALSE,scrollY = 400,scrollCollapse=TRUE,
columnDefs = list(list(width = '800%', targets = c(1)))),rownames=FALSE,colnames="Name")

}
)

enter image description here

我还发现了另一个在悬停时突出显示整行的代码:

鼠标悬停时突出显示行的示例代码

#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

在我的例子中,我希望在鼠标悬停在数据表的一行上时显示文本。我该怎么做?

最佳答案

给你:

library(shiny)
library(DT)

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

output$table <- DT::renderDataTable({
DT::datatable(iris, rownames = FALSE,
options = list(rowCallback = JS(
"function(row, data) {",
"var full_text = 'This rows values are :' + data[0] + ',' + data[1] + '...'",
"$('td', row).attr('title', full_text);",
"}")))
})
}
)

关于javascript - R Shiny : Mouse Hover Text for Datatable Rows,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54176268/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com