Learn R Programming

shinyWidgets (version 0.4.1)

sendSweetAlert: Display a Sweet Alert to the user

Description

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

Usage

sendSweetAlert(session, title = "Title", text = NULL, type = NULL,
  btn_labels = "Ok")

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 : info, success, warning or error.

btn_labels

Label(s) for button(s), can be of length 2, in which case the alert will have two buttons.

See Also

confirmSweetAlert, inputSweetAlert

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"
    )
  ),
  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