Laura Biggins
02/12/2020
There are two parts to a Shiny application
library(shiny)
ui <- fluidPage(
titlePanel("Simple app"),
radioButtons(inputId = "letter_choice",
label = "select a letter",
choices = LETTERS[1:5]),
numericInput(inputId = "number_choice",
label = "type in a number",
value = 4),
textOutput(outputId = "message")
)
server <- function(input, output) {
output$message <- renderText({
paste0("You selected the letter ", input$letter_choice,
" and the number ", input$number_choice)
})
}
shinyApp(ui, server)
The input object is a special type of named list.
From within the server code, the values of the input object can be accessed in the same way as list values.
Output function in UI code pairs with a render function in the server code.
Within the render function are instructions telling Shiny what to show the user.
library(shiny)
ui <- fluidPage(
titlePanel("Simple app"),
radioButtons(inputId = "letter_choice",
label = "select a letter",
choices = LETTERS[1:5]),
numericInput(inputId = "number_choice",
label = "type in a number",
value = 4),
textOutput(outputId = "message")
)
server <- function(input, output, session) {
output$message <- renderText({
paste0("You selected the letter ", input$letter_choice,
" and the number ", input$number_choice)
})
}
shinyApp(ui, server)