click: Click on a Shiny button

View source: R/jsFunc-click.R

clickR Documentation

Click on a Shiny button

Description

The click() function can be used to programatically simulate a click on a Shiny actionButton().

Usage

click(id, asis = FALSE)

Arguments

id

The id of the button

asis

If TRUE, use the ID as-is even when inside a module (instead of adding the namespace prefix to the ID).

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(),  # Set up shinyjs
      "Count:", textOutput("number", inline = TRUE), br(),
      actionButton("btn", "Click me"), br(),
      "The button will be pressed automatically every 3 seconds"
    ),
    server = function(input, output) {
      output$number <- renderText({
        input$btn
      })
      observe({
        click("btn")
        invalidateLater(3000)
      })
    }
  )
}

daattali/shinyjs documentation built on Nov. 16, 2023, 3:08 p.m.