相关R shiny DT hover显示详细表
我一直在研究一个应用程序,我想在这个应用程序中显示一些文本作为用户鼠标在表上。
我一直在使用上面链接中示例的修改版本,但是有一个问题。
在用户将鼠标移到表外的情况下,是否有办法将input[["cell"]]
还原为NULL
?在当前的实现中,它报告鼠标离开前触摸的最后一个值。
library(shiny)
library(DT)
data(mpg, package = "ggplot2")
callback <- c(
"table.on('mouseover', 'td', function(){",
" var index = table.cell(this).index();",
" Shiny.setInputValue('cell', index, {priority: 'event'});",
"});"
)
ui <- fluidPage(
br(),
DTOutput("tbl"),
htmlOutput("msg")
)
server <- function(input, output, session){
dat <- mpg
output[["tbl"]] <- renderDT({
datatable(
dat,
callback = JS(callback)
)
})
output[["tblfiltered"]] <- renderDT({
datatable(
filteredData(),
fillContainer = TRUE,
options = list(
pageLength = 5
)
)
})
output$msg <- renderText(paste(input[["cell"]], collapse = ","))
}
shinyApp(ui, server)
感谢stacimane Laurent的帮助
修改callback
如下
callback <- c(
"table.on('mouseover', 'td', function(){",
" var index = table.cell(this).index();",
" Shiny.setInputValue('cell', index, {priority: 'event'});",
"});,
table.on('mouseout', 'td', function(){",
" Shiny.setInputValue('cell', null, {priority: 'event'});",
"});
"
)