当我将鼠标悬停在表格列名称上时,有什么方法可以提供工具提示或弹出窗口。我基本上想要弹出一个描述R SHINY DATA TABLE中的列名。
以下是我的代码,它呈现一个表。我试图在所有论坛上搜索很多,但找不到合适的代码。
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")
}
)
答案 0 :(得分:0)
这可能会对您有所帮助:
library(shiny)
library(DT)
ui <- fluidPage(
mainPanel(
dataTableOutput("irisTable")
)
)
server <- function(input, output) {
output$irisTable <- renderDataTable(
iris[,c(4,3,1)], callback = JS("var tips = ['Row Names', 'Here goes one explanation', 'Here goes another explanation',
'And here goes a final explanation'],
header = table.columns().header();
for (var i = 0; i < tips.length; i++) {
$(header[i]).attr('title', tips[i]);
}"))
}
shinyApp(ui = ui, server = server)
答案 1 :(得分:0)
您好,您可以在参数colnames
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);",
"}"),
paging=FALSE,
searching = FALSE,
ordering=FALSE,
scrollY = 400,
scrollCollapse=TRUE,
columnDefs = list(
list(width = '800%', targets = c(1)))),
selection = 'single',
escape=FALSE,
rownames=FALSE,
colnames = c(HTML('<span title ="some popup">Here</span>'),HTML('<span title ="some other popup">Are</span>') , HTML('<span title ="yet another popup">Some</span>')))
})
}
)
希望这有帮助!