Shiny Input Controls Cheatsheet: Complete Widget Reference

Master every input control with syntax examples and validation patterns

Complete reference guide for Shiny input controls covering text inputs, selection widgets, file uploads, validation patterns, and custom styling with copy-paste code examples.

Tools
Author
Affiliation
Published

June 22, 2025

Modified

June 23, 2025

Keywords

shiny input controls cheatsheet, shiny widgets reference, shiny form validation, input controls guide, shiny interactive elements

Shiny Input Controls

Complete reference for widgets, validation, and professional form design

1 Text & Numeric Inputs

# Text input
textInput("name", "Name:", 
          placeholder = "Enter your name")

# Text area
textAreaInput("comments", "Comments:", 
              rows = 4, resize = "vertical")

# Password
passwordInput("pwd", "Password:")

# Numeric input
numericInput("age", "Age:", 
             value = 25, min = 0, max = 120)

# Slider
sliderInput("range", "Range:",
            min = 0, max = 100, value = 50)

Access Pattern

input$name → Get text value
input$age → Get numeric value
input$range → Get slider value

2 Selection Controls

# Dropdown select
selectInput("country", "Country:",
            choices = c("USA", "UK", "Canada"))

# Multiple select
selectInput("vars", "Variables:",
            choices = names(mtcars),
            multiple = TRUE)

# Radio buttons
radioButtons("gender", "Gender:",
             choices = c("Male", "Female", "Other"))

# Checkboxes
checkboxGroupInput("features", "Features:",
                   choices = c("A", "B", "C"))

# Single checkbox
checkboxInput("agree", "I agree", FALSE)

Selection Tips: Use radio buttons for ≤5 options, dropdowns for many options, checkboxes for multiple selections

3 Date & File Inputs

# Date input
dateInput("start_date", "Start Date:",
          value = Sys.Date(),
          format = "yyyy-mm-dd")

# Date range
dateRangeInput("dates", "Date Range:",
                start = Sys.Date() - 30,
                end = Sys.Date())

# File upload
fileInput("file", "Choose File:",
          accept = c(".csv", ".xlsx"))

# Multiple files
fileInput("files", "Upload Files:",
          multiple = TRUE,
          accept = "image/*")

File Access

input$file$datapath → File location
input$file$name → Original filename
input$file$size → File size in bytes

4 Action Controls

# Action button
actionButton("run", "Run Analysis",
             class = "btn-primary",
             icon = icon("play"))

# Download button
downloadButton("download", "Download CSV",
               class = "btn-success")

# Action link
actionLink("help", "Show Help",
            icon = icon("question-circle"))

# Server: Handle button clicks
observeEvent(input$run, {
  # Your action code here
  showNotification("Analysis started!")
})

Button Styling: Use btn-primary, btn-success, btn-danger for different actions

5 Input Validation

# Basic validation
observe({
  validate(
    need(input$name != "", "Name is required"),
    need(nchar(input$name) >= 2, "Name too short")
  )
})

# Real-time feedback
output$email_feedback <- renderUI({
  if (grepl("@", input$email)) {
    div(class = "text-success", 
        icon("check"), "Valid email")
  } else {
    div(class = "text-danger", 
        icon("times"), "Invalid email")
  }
})

# File validation
observe({
  req(input$file)
  validate(
    need(input$file$size < 10 * 1024^2, "File too large")
  )
})

Validation Levels

validate() → Stop execution with message
req() → Require input before proceeding
renderUI() → Show real-time feedback

6 Dynamic & Custom Inputs

# Dynamic input generation
output$dynamic_inputs <- renderUI({
  lapply(1:input$num_inputs, function(i) {
    textInput(paste0("field_", i), 
              paste("Field", i, ":"))
  })
})

# Update input choices
observe({
  updateSelectInput(session, "variable",
                    choices = names(selected_data()))
})

# Conditional inputs
conditionalPanel(
  condition = "input.data_source == 'file'",
  fileInput("upload", "Upload File:")
)

# Custom styling
textInput("styled", "Custom Input:",
          class = "form-control-lg",
          style = "border-radius: 25px;")

Dynamic Tips: Use renderUI() for dynamic inputs, updateXXXInput() for changing existing inputs



Ready to Master Shiny Input Controls?

Build professional forms and interactive interfaces with our comprehensive tutorials

Complete Input Controls Guide Master Layout Systems App Structure Cheatsheet

Professional form design • Advanced validation patterns • Mobile-responsive interfaces

placeholder

placeholder
No matching items
Back to top

Reuse

Citation

BibTeX citation:
@online{kassambara2025,
  author = {Kassambara, Alboukadel},
  title = {Shiny {Input} {Controls} {Cheatsheet:} {Complete} {Widget}
    {Reference}},
  date = {2025-06-22},
  url = {https://www.datanovia.com/learn/tools/shiny-apps/cheatsheets/input-controls.html},
  langid = {en}
}
For attribution, please cite this work as:
Kassambara, Alboukadel. 2025. “Shiny Input Controls Cheatsheet: Complete Widget Reference.” June 22, 2025. https://www.datanovia.com/learn/tools/shiny-apps/cheatsheets/input-controls.html.