我有一个关于 Shiny 应用程序中的 actionButon() 函数的问题。 在 RStudio Shiny 网站中,解释了 actionButton 包含一些将数字发送到服务器的 JavaScript 代码。当 Web 浏览器首次连接时,它会发送一个值 0,每次单击时,它都会发送一个递增值:1、2、3 等。如何在不使用按钮值的情况下知道用户何时单击按钮?
谢谢
最佳答案
shinyjs
包通过内置的 onclick
和 oneevent
提供此功能,因此您可以根据您的需求进行定制。下面的例子取自https://github.com/daattali/shinyjs/issues/33
if (interactive()) {
library(shiny)
shinyApp(
ui = fluidPage(
useShinyjs(), # Set up shinyjs
actionButton("date", "date"),
actionButton("coords", "coords"),
actionButton("disappear", "disappear"),
actionButton("text", "text")
),
server = function(input, output) {
onclick("date", alert(date()))
onclick("coords", function(event) { alert(event) })
onevent("mouseenter", "disappear", hide("text"))
onevent("mouseleave", "disappear", show("text"))
}
)
}
关于javascript - 点击操作按钮的那一刻,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46927412/