[英]R shiny DT hover how to report NULL when mouse is moved off the table
我一直在開發一個應用程序,我想在用戶將鼠標懸停在表格上時顯示一些文本。
我一直在使用上面鏈接中示例的修改版本,但是有一個掛斷。
在用戶將鼠標移出表格的情況下,有沒有辦法讓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)
感謝Stéphane 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'});",
"});
"
)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.