click: Click on a Shiny button

Description Usage Arguments Note See Also Examples

View source: R/jsFunc-click.R

Description

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

Usage

1
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

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

Example output

Attaching package: 'shinyjs'

The following objects are masked from 'package:methods':

    removeClass, show

shinyjs documentation built on Dec. 23, 2021, 5:06 p.m.