useShinyalert: Set up a Shiny app to use shinyalert

View source: R/useShinyalert.R

useShinyalertR Documentation

Set up a Shiny app to use shinyalert

Description

This function is no longer required.

The first time a {shinyalert} message is shown, the required scripts are automatically inserted to the Shiny app. Usually this is not an issue, but in some unique cases this can sometimes cause the modal to appear glitchy (such as inside RStudio's Viewer, on some old browsers, or if the modal contains certain Shiny inputs).

If you notice issues with the UI of the modal, you may want to try to pre-load the scripts when the Shiny app initializes by calling useShinyalert(force=TRUE) anywhere in the UI.

Usage

useShinyalert(rmd, force = FALSE)

Arguments

rmd

Deprecated, do not use this parameter.

force

Set to TRUE to force pre-loading the {shinyalert} scripts. If FALSE (default), you will get a warning saying this function is not required.

Value

Scripts that shinyalert requires that are automatically inserted to the app's <head> tag.

See Also

shinyalert

Examples

if (interactive()) {
  library(shiny)
  library(shinyalert)

  shinyApp(
    ui = fluidPage(
      useShinyalert(force = TRUE),  # Set up shinyalert
      actionButton("btn", "Click me")
    ),
    server = function(input, output) {
      observeEvent(input$btn, {
        # Show a simple modal
        shinyalert(title = "You did it!", type = "success")
      })
    }
  )
}

shinyalert documentation built on May 29, 2024, 12:30 p.m.