-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPermitsApp.R
84 lines (71 loc) · 3.43 KB
/
PermitsApp.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#
# This is a Shiny web application. You can run the application by clicking
# the 'Run App' button above.
#
# Find out more about building applications with Shiny here:
#
# http://shiny.rstudio.com/
#
library(shiny)
library(tidyverse)
Permits_MSA= read.csv("https://www2.census.gov/econ/bps/Metro/ma2305y.txt",skip=1)
FinalTable_MSA <- Permits_MSA[,5:17]
FipsToState <- read_csv("Data/FipsToState.csv")
# Prepping the Permits table from the census
colnames(FinalTable_MSA)<-c("Area", 'Single-family Permits Bldgs','Single-family Permits Units'
,'Single-family Permits Value','Two-family Permits Bldgs','Two-family Permits Units'
,'Two-family Permits Value','3-4 family Permits Bldgs','3-4 family Permits Units'
,'3-4 family Permits Value','5+ family Permits Bldgs','5+ family Permits Units'
,'5+ family Permits Value')
Permits_Countys=read.csv('https://www2.census.gov/econ/bps/County/co2305y.txt',skip=1)
FinalTable_County <- Permits_Countys[,c(2,6:18)]
FinalTable_County %>%
left_join(FipsToState,by=c("State"="FIPS_Code")) %>%
mutate(State=Postal_Abbr.) %>%
select(c(1:14))->FinalTable_County
FinalTable_County$Area<-paste(FinalTable_County$Name,FinalTable_County$State,sep="")
FinalTable_County=FinalTable_County[,-c(1:2)]
FinalTable_County = relocate(FinalTable_County,Area)
colnames(FinalTable_County)<-c("Area", 'Single-family Permits Bldgs','Single-family Permits Units'
,'Single-family Permits Value','Two-family Permits Bldgs','Two-family Permits Units'
,'Two-family Permits Value','3-4 family Permits Bldgs','3-4 family Permits Units'
,'3-4 family Permits Value','5+ family Permits Bldgs','5+ family Permits Units'
,'5+ family Permits Value')
FinalDataFrame <- rbind(FinalTable_MSA,FinalTable_County)
# Define UI for application that creates table for Permits at County or MSA Level
ui <- fluidPage(
# Application title
titlePanel("Local HBA Data"),
# Sidebar with a input and output definitions
sidebarLayout(
sidebarPanel(
# Input: Choose Data set
selectizeInput("dataset", # Once Incorporate Multiple Selections
label=NULL,choices=NULL,multiple = TRUE,options=list(maxOptions=20
,placeholder="Select a MSA or County"))
),
# Button
downloadButton("downloadData","Click Here to Download",class = "btn-lg btn-success")),
# main panel to display output
mainPanel(textOutput("table"),
tableOutput("finalTable")),
)
# Display of the table
server <- function(input, output, session) {
updateSelectizeInput(session,"dataset",choices=FinalDataFrame$Area,server=TRUE)
data <- reactive({
FinalDataFrame[FinalDataFrame$Area %in% input$dataset,]
})
output$table <- renderText({
paste(paste(input$dataset,sep=","),"Permits YTD as of May 2023. (Valuation in thousands for MSA, County Valuation is USD)")
})
output$finalTable <- renderTable({
data()
})
output$downloadData <- downloadHandler(
filename = function(){paste("Permits",Sys.Date(),".csv",sep="")},
content = function(file){write.csv(data(),file)}
)
}
# Run the application
shinyApp(ui = ui, server = server)