保存 shinyalert 的变量输出
Save variable output from shinyalert
我想保存 shinyalert 警告 (https://github.com/daattali/shinyalert). This post is helpful for printing the value to console () 的输出结果 (TRUE/FALSE),但我无法将值本身保存为变量。
library(shiny)
library(shinyalert)
ui <- fluidPage(
useShinyalert()
)
server <- function(input, output) {
shinyalert(
title = "Warning",
text = "Some warning",
closeOnEsc = FALSE,
closeOnClickOutside = FALSE,
type = "warning",
showConfirmButton = TRUE,
showCancelButton = TRUE,
confirmButtonText = "OK",
cancelButtonText = "Cancel",
animation = TRUE,
callbackR = mycallback
)
}
shinyApp(ui, server)
这将自动打印以控制 shinyalert 的值。将 shinyalert 设置为变量或函数中的值似乎没有任何作用:
mycallback <- function(value) {
test_var=value
}
在这种情况下忘记函数,只需使用 observeEvent 观察警报,因为可以通过 input$shinyalert 访问回调值。
alert<-shinyalert(
title = "Warning",
text = "Some warning",
closeOnEsc = FALSE,
closeOnClickOutside = FALSE,
type = "warning",
showConfirmButton = TRUE,
showCancelButton = TRUE,
confirmButtonText = "OK",
cancelButtonText = "Cancel",
animation = TRUE,
callbackR = NULL
)
observeEvent(input$shinyalert,
value<<-input$shinyalert
)
注意:我已经将值变量赋值为全局变量,请确保你真的赋值了它。
编辑:
这似乎只在应用程序关闭时分配值,因为服务器上没有发生任何其他事情。为了弥补这一点,我添加了一个用于测试目的的按钮,因为一旦另一个命令在服务器上通过,就会分配该值。
observeEvent(input$test,
print(value)
)
编辑:
如果我们想在后续语句中使用该值 w/o 首先在服务器中执行任何其他操作,我们将必须使用 callbackR 函数。
mycallback<-function(value){
if(value==T){
print(value) #commands
} else if (value==F){
print(value) #commands
}
}
注意:这个包还比较新,有很多错误,例如,如果你试图将这些模式链接在一起,因为包的作者声称这个包可以做到,那是行不通的。
shinyalert(
title = "What is your name?", type = "input",
callbackR = function(value) { shinyalert(paste("Welcome", value)) }
)
这里是link对作者的描述。
https://deanattali.com/blog/shinyalert-package/
如此处所述...https://github.com/daattali/shinyalert/issues/14
如果您安装来自 github 的最新版本,其中许多错误将得到修复。查看报告的与此软件包相关的错误,我们不是唯一遇到此问题的人。
我想保存 shinyalert 警告 (https://github.com/daattali/shinyalert). This post is helpful for printing the value to console (
library(shiny)
library(shinyalert)
ui <- fluidPage(
useShinyalert()
)
server <- function(input, output) {
shinyalert(
title = "Warning",
text = "Some warning",
closeOnEsc = FALSE,
closeOnClickOutside = FALSE,
type = "warning",
showConfirmButton = TRUE,
showCancelButton = TRUE,
confirmButtonText = "OK",
cancelButtonText = "Cancel",
animation = TRUE,
callbackR = mycallback
)
}
shinyApp(ui, server)
这将自动打印以控制 shinyalert 的值。将 shinyalert 设置为变量或函数中的值似乎没有任何作用:
mycallback <- function(value) {
test_var=value
}
在这种情况下忘记函数,只需使用 observeEvent 观察警报,因为可以通过 input$shinyalert 访问回调值。
alert<-shinyalert(
title = "Warning",
text = "Some warning",
closeOnEsc = FALSE,
closeOnClickOutside = FALSE,
type = "warning",
showConfirmButton = TRUE,
showCancelButton = TRUE,
confirmButtonText = "OK",
cancelButtonText = "Cancel",
animation = TRUE,
callbackR = NULL
)
observeEvent(input$shinyalert,
value<<-input$shinyalert
)
注意:我已经将值变量赋值为全局变量,请确保你真的赋值了它。
编辑: 这似乎只在应用程序关闭时分配值,因为服务器上没有发生任何其他事情。为了弥补这一点,我添加了一个用于测试目的的按钮,因为一旦另一个命令在服务器上通过,就会分配该值。
observeEvent(input$test,
print(value)
)
编辑: 如果我们想在后续语句中使用该值 w/o 首先在服务器中执行任何其他操作,我们将必须使用 callbackR 函数。
mycallback<-function(value){
if(value==T){
print(value) #commands
} else if (value==F){
print(value) #commands
}
}
注意:这个包还比较新,有很多错误,例如,如果你试图将这些模式链接在一起,因为包的作者声称这个包可以做到,那是行不通的。
shinyalert(
title = "What is your name?", type = "input",
callbackR = function(value) { shinyalert(paste("Welcome", value)) }
)
这里是link对作者的描述。 https://deanattali.com/blog/shinyalert-package/
如此处所述...https://github.com/daattali/shinyalert/issues/14 如果您安装来自 github 的最新版本,其中许多错误将得到修复。查看报告的与此软件包相关的错误,我们不是唯一遇到此问题的人。