Action Link

#| standalone: true
#| components: [viewer]
#| viewerHeight: 200

library(shiny)
library(bslib)

ui <- page_fixed(
  actionLink("update", "Print the time"),
  textOutput("time")
)

server <- function(input, output) {

  output$time <- renderText({ 
    format(Sys.time(), "%a %b %d %X %Y") 
  }) |>
    bindEvent(input$update) 

}

shinyApp(ui = ui, server = server)
library(shiny)
library(bslib)

ui <- page_fixed(
  actionLink("update", "Print the time"), 
  textOutput("time")
)

server <- function(input, output) {

  output$time <- renderText({ 
    format(Sys.time(), "%a %b %d %X %Y") 
  }) |>
    bindEvent(input$update) 

}

shinyApp(ui = ui, server = server)
No matching items

Relevant Functions

  • actionLink
    actionLink(inputId, label, icon = NULL, ...)

  • bindEvent
    bindEvent(x, ..., ignoreNULL = TRUE, ignoreInit = FALSE, once = FALSE, label = NULL)

No matching items

Details

An action link appears as a link in your app and has a value that increments each time the user presses the link. Combine an action link with bindEvent() to specify what should happen when a user clicks the link.

Follow these steps to add an action link to your app:

  1. Add actionLink() to the UI of your app to create an action link. Where you call this function will determine where the link will appear within the app’s layout.

  2. Specify the inputId and label parameters of actionLink() to define the link’s identifier and label.

The value of an input component is accessible as a reactive value within the server() function. To access the value of an action link:

  1. Use input$<inputId> to access the value of the action link, where <inputId> is the identifier of the link, (e.g., input$go). The value is an integer that represents the number of times the action link has been clicked.

Action links are almost never used for their literal value, but to trigger a change that can be observed by bindEvent(). To specify what should happen when the user clicks the action link:

  1. First, specify the action that should occur on click (via a observe(), reactive(), or render*() object).

  2. Pipe the object from 1 into bindEvent(), and also supply the input value of the action button. This will prevent the object 1 from executing until the action button is clicked.

See also