R Shiny: Mouse Hover Text for Datatable Rows(R Shiny:数据表行的鼠标悬停文本)
问题描述
Is there a way to display mouseover text upon hovering over a row (record) in datatable display? After going through some similar questions on StackOverflow, I found 2 example codes, one that displays hover text for a column cell and one that highlights the entire row on mouse hover.
Example code for displaying column cell hover text:
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")
}
)
I also found another code that highlights the entire row upon hover:
Example code for highlight row on mouse hover
#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))
In my case, I wish to display text upon mouse hover over a row of the datatable. How shall I do that?
Here you go:
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);",
"}")))
})
}
)
这篇关于R Shiny:数据表行的鼠标悬停文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:R Shiny:数据表行的鼠标悬停文本
基础教程推荐
- 动态更新多个选择框 2022-01-01
- 当用户滚动离开时如何暂停 youtube 嵌入 2022-01-01
- 在for循环中使用setTimeout 2022-01-01
- 在 JS 中获取客户端时区(不是 GMT 偏移量) 2022-01-01
- 有没有办法使用OpenLayers更改OpenStreetMap中某些要素 2022-09-06
- 响应更改 div 大小保持纵横比 2022-01-01
- 悬停时滑动输入并停留几秒钟 2022-01-01
- 我什么时候应该在导入时使用方括号 2022-01-01
- Karma-Jasmine:如何正确监视 Modal? 2022-01-01
- 角度Apollo设置WatchQuery结果为可用变量 2022-01-01