Inputs

Building Web Applications with Shiny in R

Kaelen Medeiros

Data Scientist

Example inputs

Shiny provides a variety of inputs to choose from.

Slider input to select a year from 1900 to 2000

Select Input to select dogs or cats

Numerical input to input a number, currently showing 2

Date range input to input a birthday between 1920 and the present

Building Web Applications with Shiny in R

Input functions

selectInput("inputId", 
            "label", 
            choices = c("A", "B", "C"))
sliderInput("inputId",
            "label",
            value = 1925,
            min = 1900,
            max = 2000)
?dateRangeInput
help(checkboxInput)
Building Web Applications with Shiny in R

Where to use inputs

ui <- fluidPage(
  textInput("name", "Enter a name:"),
  selectInput("animal", "Dogs or cats?", choices = c("dogs", "cats")),
  textOutput("greeting"),
  textOutput("answer")
)

server <- function(input, output, session) { output$greeting <- renderText({ paste("Do you prefer dogs or cats,", input$name, "?") }) output$answer <- renderText({ paste("I prefer", input$animal, "!") }) }
Building Web Applications with Shiny in R

Let's practice!

Building Web Applications with Shiny in R

Preparing Video For Download...