delay {shinyjs} | R Documentation

## 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.

### Note

`shinyjs` must be initialized with a call to `useShinyjs()` in the app's ui.

### See Also

`useShinyjs`, `runExample`

### Examples

    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())
          })
        }
      )
    }

[Package shinyjs version 0.8 Index]