# NOT RUN {
# Example 1: Simple modal
if (interactive()) {
library(shiny)
library(shinyalert)
shinyApp(
ui = fluidPage(
actionButton("btn", "Click me")
),
server = function(input, output) {
observeEvent(input$btn, {
# Show a simple modal
shinyalert(title = "You did it!", type = "success")
})
}
)
}
# Example 2: Simple input modal calling another modal in its callback
if (interactive()) {
library(shiny)
library(shinyalert)
shinyApp(
ui = fluidPage(
actionButton("btn", "Greet")
),
server = function(input, output) {
observeEvent(input$btn, {
shinyalert(
title = "What is your name?", type = "input",
callbackR = function(value) { shinyalert(paste("Welcome", value)) }
)
})
}
)
}
# Example 3: Modal with Shiny tags (input and output)
if (interactive()) {
library(shiny)
library(shinyalert)
shinyApp(
ui = fluidPage(
actionButton("btn", "Go")
),
server = function(input, output) {
observeEvent(input$btn, {
shinyalert(
html = TRUE,
text = tagList(
numericInput("num", "Number", 10),
"The square of the number is",
textOutput("square", inline = TRUE)
)
)
})
output$square <- renderText({ input$num*input$num })
}
)
}
# }
Run the code above in your browser using DataLab