Learn R Programming

shinyjs (version 2.0.0)

delay: Execute R code after a specified number of milliseconds has elapsed

Description

You can use delay if you want to wait a specific amount of time before running code. This function can be used in combination with other shinyjs functions, such as hiding or resetting an element in a few seconds, but it can also be used with any code as long as it's used inside a Shiny app.

Usage

delay(ms, expr)

Arguments

ms

The number of milliseconds to wait (1000 milliseconds = 1 second) before running the expression.

expr

The R expression to run after the specified number of milliseconds has elapsed.

See Also

useShinyjs, runExample

Examples

Run this code
# NOT RUN {
if (interactive()) {
  library(shiny)
  shinyApp(
    ui = fluidPage(
      useShinyjs(),
      p(id = "text", "This text will disappear after 3 seconds"),
      actionButton("close", "Close the app in half a second")
    ),
    server = function(input, output) {
      delay(3000, hide("text"))
      observeEvent(input$close, {
        delay(500, stopApp())
      })
    }
  )
}
# }

Run the code above in your browser using DataLab