Learn R Programming

shinyWidgets (version 0.4.0)

useSweetAlert: Display a Sweet Alert

Description

Send a message from the server and launch a sweet alert in the UI.

Usage

useSweetAlert()

sendSweetAlert(session, title = "Title", text = "Text", type = NULL, html = FALSE)

Arguments

session

The session object passed to function given to shinyServer.

title

Title of the alert

text

Text of the alert

type

Type of the alert : null, info, success, warning or error

html

Logical. Use HTML in the text

Examples

Run this code
# NOT RUN {
if (interactive()) {

shinyApp(
  ui = fluidPage(
    tags$h1("Click the button"),
    actionButton(inputId = "success", label = "Launch a success sweet alert"),
    actionButton(inputId = "error", label = "Launch an error sweet alert"),
    useSweetAlert()
  ),
  server = function(input, output, session) {
    observeEvent(input$success, {
      sendSweetAlert(
        session = session, title = "Success !!", text = "All in order", type = "success"
      )
    })
    observeEvent(input$error, {
      sendSweetAlert(
        session = session, title = "Error !!", text = "It's broken...", type = "error"
      )
    })
  }
)

}
# }
# NOT RUN {
# }

Run the code above in your browser using DataLab