Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
capellett committed Dec 10, 2024
1 parent 80a826f commit bbb6044
Showing 1 changed file with 52 additions and 20 deletions.
72 changes: 52 additions & 20 deletions app.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,38 +5,70 @@
library(shiny)
library(tidyverse)
library(DT)
library(bslib)

# load("data/pop19.rda")
# load("data/pop22.rda")
load("data/pop_proj.rda")

downloadButton <- function(...) {
tag <- shiny::downloadButton(...)
tag$attribs$download <- NULL
tag
}

## ui
ui <- fluidPage(
titlePanel("Population Data Explorer"),
titlePanel("South Carolina Population Projection Data Explorer"),

sidebarLayout(

sidebarPanel(
selectInput("dataset", "Choose a dataset:",
choices = c("pop19",
"pop22")),
selectInput('county', 'Choose a county:', choices = NULL)),
mainPanel(
DT::dataTableOutput("table")
)))
checkboxGroupInput(
inputId = "vintage", label = "Choose a data vintage:",
choices = unique(pop_proj$Edition), selected = "2022"),
selectInput(
inputId = 'county',
label = 'Choose a county:',
choices = unique(pop_proj$County),,
selected = 'SOUTH CAROLINA'),
sliderInput(
inputId = "year",
label = "Choose a range of years:",
min = min(pop_proj$Year, na.rm=T),
max = max(pop_proj$Year, na.rm=T),
value = c(min(pop_proj$Year, na.rm=T), max(pop_proj$Year, na.rm=T)),
step = 1, sep=''),
downloadButton('downloadData', 'Download Data')),

mainPanel(plotOutput("plot"))
))

server <- function(input, output, session) {

# data <- reactive({
# switch(input$dataset,
# "pop19" = pop19,
# "pop22" = pop22)
# })
data <- shiny::reactive({
pop_proj |>
dplyr::filter(
Edition %in% input$vintage &
County %in% input$county &
Year >= input$year[1] & Year <= input$year[2])
})

# observe({
# updateSelectInput(session, 'county', 'Choose a county:', choices = unique(data()$County))
# })
output$plot <- shiny::renderPlot({
ggplot2::qplot(1:10, 1:10)
})

output$table <- DT::renderDataTable({
iris # data()
data()
})

output$downloadData <- downloadHandler(
filename = function() {
paste("scpopulation_", input$county, '_', input$vintage, ".csv", sep="")
},
content = function(file) {
write.csv(data(), file)
}
)

}

shinyApp(ui, server)
shiny::shinyApp(ui, server)

0 comments on commit bbb6044

Please sign in to comment.