【问题标题】:Moment of click on action button点击动作按钮的瞬间
【发布时间】:2017-10-25 08:21:37
【问题描述】:
我有一个关于闪亮应用程序中的 actionButon() 函数的问题。
在 RStudio Shiny 网站中,解释了 actionButton 包含一些将数字发送到服务器的 JavaScript 代码。当网络浏览器第一次连接时,它会发送一个值 0,每次点击时,它都会发送一个递增的值:1、2、3,以此类推。不使用按钮的值,如何知道用户何时点击了按钮?
谢谢
【问题讨论】:
标签:
javascript
shiny
action-button
【解决方案1】:
shinyjs 包通过内置的onclick 和onevent 具有此功能,因此您可以根据需要定制。下面的例子取自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"))
}
)
}