I have a simple user interface that asks two questions and takes two user defined values as responces. I have implmented this using the latest version of shinyalert using the new features that allow input controls to be defined in the modals. An example of the process is shown here:
library(shiny)
library(shinyalert)
ui <- fluidPage(
useShinyalert(),
tags$h2("Demo shinyalert"),
tags$br(),
fluidRow(
column(
width = 6,
actionButton("shinyalert_popup",
"Alert Popup")
)
),
fluidRow(
verbatimTextOutput(outputId = "return_value_1"),
verbatimTextOutput(outputId = "return_value_2")
)
)
server <- function(input, output, session) {
observeEvent(input$shinyalert_popup, {
shinyalert(
title = "Input Number 1",
text = tagList(
"Enter a number",
textInput(inputId = "shinyalert_value_1",
label = "")
),
html = TRUE,
inputId = "shinyalert_modal",
showConfirmButton = TRUE,
confirmButtonText = "OK",
callbackR = function() {
shinyalert(
title = "Input Number 2",
text = tagList(
"Enter another number",
textInput(inputId = "shinyalert_value_2",
label = "")
),
html = TRUE,
inputId = "shinyalert_callback",
showConfirmButton = TRUE,
confirmButtonText = "OK"
)
}
)
})
output$return_value_1 <- renderPrint(input$shinyalert_value_1)
output$return_value_2 <- renderPrint(input$shinyalert_value_2)
}
shinyApp(ui = ui, server = server)
I have a simple user interface that asks two questions and takes two user defined values as responces. I have implmented this using the latest version of
shinyalertusing the new features that allow input controls to be defined in the modals. An example of the process is shown here:The responce shows that the first input, from the id
shinyalert_value_1is captured and updates in the ui. The second input, fromshinyalert_value_2, which is nested in thecallbackRparameter shows aNULLwhen values are typed and after the modal has been closed. This indicates that theinput$shinyalert_value_2is not found in this configuration.