Closed nick-youngblut closed 6 months ago
Could you please provide a small reprex? I tried taking your code and making a small app from it, and it does run successfully.
library(shinyalert)
library(shiny)
ui <- fluidPage(
actionButton('submit', 'submit')
)
server <- function(input, output, session) {
observeEvent(input$submit, {
shinyalert::shinyalert(
text = "Are you ready to submit?",
type = "info",
html = TRUE,
showCancelButton = TRUE,
confirmButtonText = "Yes!",
cancelButtonText = "Not yet...",
inputId = "shinyalert_validation"
)
})
}
shinyApp(ui, server)
I fixed the issue by using a reactive object with the callbackR
parameter:
shinyalert_validation_react = reactiveVal(NULL)
observeEvent(input$submit, { # action button
# validate input
msg = validate_samples_table(
DF = DF,
input = input
)
# show pop-up
if(msg$type %in% c("success", "warning")){
# Success/Warning
shinyalert::shinyalert(
title = msg$header,
text = paste(msg$text, "Are you ready to submit?"),
type = "info",
html = TRUE,
showCancelButton = TRUE,
confirmButtonText = "Yes!",
cancelButtonText = "Not yet...",
inputId = "shinyalert_validation"
callbackR = \(x) shinyalert_validation_react(x)
)
} else {
# if error message, show error
shinyalert::shinyalert(msg$header, msg$text, type=msg$type)
return(NULL)
}
}
observer ({
req(shinyalert_validation_react())
# complete next step only if user presses the `Yes!` button
})
I'm glad you found a fix! But if you still think there is a bug, please do share a reproducible example so that I can look into it.
Thanks for following up on this! I don't think that it is a bug, but maybe more docs/examples on using the callbackR
parameter could be useful.
I have a problem similar to https://github.com/daattali/shinyalert/issues/60.
My code:
If the user clicks the "Yes!" button in the pop-up, and then re-clicks the "submit" action button (which should trigger the validation and pop-up again), the pop-up is skipped, and no validation occurs.
I've tried using
shinyjs::reset("shinyalert_validation")
, but it does not reset theshinyalert_validation
input.Unlike https://github.com/daattali/shinyalert/issues/60, the shinyalert is not wrapped in
renderUI()
.