Get startedGet started for free

Adding inputs

Inputs are Shiny's way of allowing users to interact with an app. For example, textInput() is used to let the user enter text and numericInput() lets the user select a number. In the next chapter we will see many other types of inputs.

To add an input to your app, simply add the input function inside fluidPage(). Recall from the video that all input functions have the same first two arguments: inputId and label.

This exercise is part of the course

Case Studies: Building Web Applications with Shiny in R

View Course

Exercise instructions

  • Define the UI for the Shiny application.
  • Create a numeric input with ID "age" and a descriptive label of "How old are you?".
  • Create a text input with ID "name" and a label of "What is your name?".

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

library(shiny)

# Define UI for the application
ui <- ___(
  # Create a numeric input with ID "age" and label of
  # "How old are you?"
  numericInput(___, ___, value = 20),
  
  # Create a text input with ID "name" and label of 
  # "What is your name?"
  ___(___, ___)
)

# Define the server logic
server <- function(input, output) {}

# Run the application
shinyApp(ui = ui, server = server)
Edit and Run Code