在我的代码中,我设置了一个删除项目的闪亮警报,但要使其正常工作,用户需要单击两次按钮,因为第一个响应始终为FALSE。我假设它是因为FALSE是初始值,并且该函数输出值,然后将其更改为新的响应。有办法解决吗?
虚拟代码:
library(shiny)
library(shinyalert)
shinyApp(
ui = fluidPage(
useShinyalert(), # Set up shinyalert
actionButton("btn", "Delete")
),
server = function(input, output) {
global <- reactiveValues(response = FALSE)
observeEvent(input$btn, {
shinyalert(
title = "Are you sure you want to delete this file?",
callbackR = function(x) {
global$response <- x
},
text = "You will not be able to recover this imaginary file!",
type = "warning",
showCancelButton = TRUE,
confirmButtonCol = '#DD6B55',
confirmButtonText = 'Yes, delete it!'
)
print(global$response)
})
}
)