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

Description Usage Arguments Note See Also Examples

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

1
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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
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())
      })
    }
  )
}

YTLogos/shinyjs documentation built on May 21, 2019, 1:41 a.m.