Outputs

Building Web Applications with Shiny in R

Kaelen Medeiros

Data Scientist

Render functions

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

server <- function(input, output, session) {
  output$question <- 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

Other render functions

Building Web Applications with Shiny in R

Output functions

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

textOutput("question"), textOutput("answer")
)
Building Web Applications with Shiny in R

Other output functions

  • tableOutput() or dataTableOutput
  • imageOutput()
  • plotOutput()
Building Web Applications with Shiny in R

Non-Shiny output and render functions

library(shiny)
library(babynames)

ui <- fluidPage(
  DT::DTOutput("babynames_table")
)

server <- function(input, output){
  output$babynames_table <- DT::renderDT({
    babynames %>% 
      dplyr::slice_sample(prop = .1) %>%
      DT::datatable()
  })
}

shinyApp(ui = ui, server = server)

An interactive data table displaying a random 10% of the babynames dataset

Building Web Applications with Shiny in R

Let's practice!

Building Web Applications with Shiny in R

Preparing Video For Download...