forked from dcdykstra/479_1_Proj
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.R
161 lines (151 loc) · 5.38 KB
/
app.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
library(shiny)
library(bslib)
library(htmltools)
library(shinydashboard)
library(tidyverse)
library(ggplot2)
library(sf)
library(raster)
library(scales)
library(usmap)
library(leaflet)
library(ggrepel)
library(patchwork)
# Data Preparation --------------------------------------------------------
source("preprocess.R")
# source("kriging.R")
# Plot Function -----------------------------------------------------------
source("plot.R")
# UI ----------------------------------------------------------------------
ui = dashboardPage(
header = dashboardHeader(title = "Parking Dashboard"),
sidebar = dashboardSidebar(
sidebarMenu(
menuItem("Introduction", icon = icon("info"), tabName = "intro"),
menuItem("Map", icon = icon("map"), tabName = "map"),
menuItem("Summary Plots", icon = icon("chart-bar"), tabName = "sum"),
menuItem("Modeling", icon = icon("cubes"), tabName = "model"),
menuItem("About", icon = icon("user"), tabName = "about")
)
),
body = dashboardBody(
tags$head(tags$style(includeCSS("www/style.css"))),
tabItems(
tabItem(tabName = "intro",
box(width = 12, status = "primary",
includeMarkdown("www/intro.md")
)
),
tabItem(tabName = "map",
box(title="Observed Areas", width = 12, status = "warning",
column(6,
selectInput(
"stateSelect", "Select a state",
choices = c("All Across US",
sort(unique(parking$State)))
)
),
column(6,
selectInput("citySelect", "Select a city",
choices = sort(unique(parking$City)))),
),
box(width = 12, status = "primary", style="aspect-ratio:16/9",
leafletOutput("leaflet", height = "100%"))
),
tabItem(tabName = "sum",
fluidRow(
column(6,
box(status = "primary", width = 12,
selectInput("varBarSelect", "Select variable", choices = varnames),
plotOutput("bar_top", height = "600px")
),
),
column(6,
box(status = "primary", width = 12,
selectInput("varScatterSelect", "Select variable", choices = varnames),
plotOutput("scatter")
),
box(status = "info", width = 12,
fluidRow(
column(4,
selectInput(
"stateHistSelect", "Select a state",
choices = c("All states", sort(unique(parking$State)))
)
),
column(4,
selectInput(
"cityHistSelect", "Select a city",
choices = c("All cities in this state", sort(unique(parking$City))))
),
column(4,
selectInput("varHistSelect", "Select variable", choices = varnames),
)
),
plotOutput("hist")
)
),
)
),
tabItem(tabName = "model",
box(title = "Kriging Interpolation",
p("We use Kriging method to interpolate the parking",
"lot finding time for areas without data, by changing",
" the threshold you might be able to identify the most ",
"difficult area for parking"),
fluidRow(
column(6,
selectInput("krigCity", "Select City", choices = names(krig))),
column(6,
sliderInput("krigThre", "Select Threshold",
value = 0.7, min = 0, max = 1, ticks=FALSE))
),
leafletOutput("krig", width = "100%", height = "600px"),
width = 8
)
),
tabItem(tabName = "about",
box(width = 12, status = "info",
includeMarkdown("www/about.md")
)
)
)
)
)
# Server ------------------------------------------------------------------
server = function(input, output, session) {
observe({
if(input$stateSelect != "All Across US") {
updateSelectInput(
session, "citySelect",
choices = parking %>%
filter(State == input$stateSelect) %>%
pull(City) %>% unique() %>% sort()
)
}
})
leaflet_ds = reactive(
if(input$stateSelect == "All Across US" ||
is.null(input$citySelect)) parking
else dplyr::filter(parking, City == input$citySelect,
State == input$stateSelect)
)
output$leaflet = renderLeaflet(plot_leaflet(leaflet_ds()))
output$krig = renderLeaflet(plot_krig_new(krig[[input$krigCity]], input$krigThre))
output$bar_top = renderPlot(plot_bar_top(county_mean, input$varBarSelect))
output$scatter = renderPlot(plot_scatter(county_mean, input$varScatterSelect))
observe({
if(input$stateHistSelect != "All states") {
city_choices = parking %>%
filter(State == input$stateHistSelect) %>%
pull(City) %>% unique() %>% sort()
updateSelectInput(
session, "cityHistSelect",
choices = c("All cities in this state", city_choices)
)
}
})
output$hist = renderPlot(
plot_hist(input$stateHistSelect, input$cityHistSelect, input$varHistSelect))
}
shinyApp(ui, server)