# R packages
library(shiny)
library(tidyverse)
# data preps
data(storms)
<- storms |>
stormNames select(name, year) |>
distinct() |>
group_by(name) |>
summarize(count = n()) |>
arrange(desc(count))
# ui
<- fluidPage(
ui
)
# server
<- function(input, output, session) {
server
}
shinyApp(ui, server)
Shiny Exercise 2
Render Outputs
Goal: Display Storm Name Counts in a Shiny App.
Click to Check the Complete Shiny App Code!
# R packages
library(shiny)
library(tidyverse)
# data preps
data(storms)
<- storms |>
stormNames select(name, year) |>
distinct() |>
group_by(name) |>
summarize(count = n()) |>
arrange(desc(count))
# ui
<- fluidPage(
ui "The most common storm name is",
# 1. topNameText
textOutput("topNameText", inline = TRUE),
p("The table below shows the most common storm names."),
# 2. topNamesTable
tableOutput("topNamesTable"),
"The plot below shows the distribution of storm name use.",
# 3. nameDist
plotOutput("nameDist")
)
# server
<- function(input, output, session) {
server
# 1. topNameText
$topNameText <- renderText({
outputslice(stormNames, 1)$name
})
# 2. topNamesTable
$topNamesTable <- renderTable({
outputslice(stormNames, 1:5)
})
# 3. nameDist
$nameDist <- renderPlot({
outputggplot(data = stormNames) +
geom_histogram(aes(x = count), binwidth = 1) +
theme_minimal()
})
}
shinyApp(ui, server)