Building Web Applications with Shiny in R
Kaelen Medeiros
Data Scientist
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, "!")
})
}
renderTable()
renderImage()
renderPlot()
ui <- fluidPage( textInput("name", "Enter a name:"), selectInput("animal", "Dogs or cats?", choices = c("dogs", "cats")),
textOutput("question"), textOutput("answer")
)
tableOutput()
or dataTableOutput
imageOutput()
plotOutput()
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)
Building Web Applications with Shiny in R