controlInput: Control how input controller value is sent to the server

View source: R/controlInput.R

controlInputR Documentation

Control how input controller value is sent to the server

Description

Wrap Shiny input controller to: - detect whether its value was changed by the user or programmatically (with 'update*' functions), - block sending the value to the server depending on the change source, - attach custom attributes to the input value.

The original input handler (e.g. converting 'shiny::dateInput' value to 'Date') is applied before attributes are attached.

Usage

controlInput(controller, block = NULL, trigger = TRUE, attributes = list())

Arguments

controller

Shiny input controller e.g. 'shiny::selectInput' or 'shinyWidgets::pickerInput'.

block

Sources of value change that should not be sent to the server. Any of '"user"' (change made directly in the browser) and '"program"' (change made with 'update*' function). The initial value is always sent.

trigger

When 'TRUE', the value has '"trigger"' attribute attached that stores source of the change: '"init"' (initial value or the controller was rendered), '"user"' or '"program"'.

attributes

Named list of extra (static) attributes attached to the input value.

Details

The attributes can't be attached to 'NULL' values, so in this case the input value is passed as is.

Value

Nested list of 'shiny.tag' objects - the 'controller' with extra attributes and dependency attached.

Examples

if (interactive()) {
  library(shiny)

  ui <- fluidPage(
    controlInput(selectInput("letter", "Letter", letters), attributes = list(group = "form")),
    controlInput(numericInput("number", "Number", value = 1), block = "program"),
    actionButton("update", "Update programmatically"),
    verbatimTextOutput("out")
  )

  server <- function(input, output, session) {
    output$out <- renderPrint({
      str(list(letter = input$letter, number = input$number))
    })
    observeEvent(input$update, {
      updateSelectInput(session, "letter", selected = sample(letters, 1))
      # value updated in browser but not sent to the server
      updateNumericInput(session, "number", value = sample(1:10, 1))
    })
  }

  shinyApp(ui, server)
}

shinyGizmo documentation built on Nov. 27, 2026, 5:07 p.m.