-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathserver.R
342 lines (291 loc) · 21.6 KB
/
server.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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
#
# This is the server logic of a Shiny web application. You can run the
# application by clicking 'Run App' above.
#
# Find out more about building applications with Shiny here:
#
# http://shiny.rstudio.com/
#
library(shiny)
library(DT)
library(dplyr)
library(plotrix)
library(rgdal)
library(shinyWidgets)
library(spatialEco)
formatMoney <- function(x, ...) {
paste0("$", formatC(as.numeric(x), format="f", digits=2, big.mark=","))
}
shinyServer(function(input, output) {
getData <- reactive({
if(input$type != 'All'){
e <- subset(Energy_Parsed_Df, `Property Type` == input$type & year_built >= input$year)
} else{
e <- subset(Energy_Parsed_Df, year_built >= input$year)
}
e <- subset(e, select=c(Address, Property_Name, `Property Type`, year_built, Kwh_potential, sunlight_hours, sqft_available, Cost_of_installation_gross, Total_Site_Energy_Kwh, lat, lng))
return(e)
})
output$energy_table <- renderDataTable({
if(input$type != 'All'){
e <- subset(Energy_Parsed_Df, `Property Type` == input$type & year_built >= input$year & sqft_available >= input$sqft_min & Kwh_potential >= input$kwh_min)
} else{
e <- subset(Energy_Parsed_Df, year_built >= input$year & sqft_available >= input$sqft_min & Kwh_potential >= input$kwh_min)
}
e <<- e %>% as.data.frame() %>%
dplyr::select(Address, Property_Name, `Property Type`, year_built, Kwh_potential, sunlight_hours, sqft_available, Cost_of_installation_gross) %>%
mutate(Kwh_potential = as.integer(Kwh_potential), sunlight_hours = as.integer(sunlight_hours), sqft_available = as.integer(sqft_available), Cost_of_installation_gross = prettyNum(Cost_of_installation_gross, big.mark = ',')) %>%
rename(`Kwh Potential` = Kwh_potential, `Yr. Hours Sunlight` = sunlight_hours, `Roof sqft Exponsed` = sqft_available, `Solar Cost` = Cost_of_installation_gross)
}, options = list(scrollX = TRUE, order = list(list(4, 'desc')), columnDefs = list(list(className = 'dt-center', targets = 0:7))))
output$scenario_lists <- renderUI({
if(input$land_building == "Boston Buildings"){
pickerInput(
label = "Choose Property Types", inputId = 'prop_types',multiple = TRUE, selected = 'Boston All',
choices = c('Boston All',unique(Energy_Parsed_Df$`Property Type`))
)
} else if (input$land_building == "BPDA Owned Land"){
pickerInput(
label = "Choose Property Types", inputId = 'prop_types',multiple = TRUE, selected = 'BPDA All',
choices = c('BPDA All',unique(as.character(land_parcels$type)))
)
} else if (input$land_building == 'Both'){
pickerInput(
label = "Choose Property Types", inputId = 'prop_types',multiple = TRUE, selected = 'All',
choices = c('All','Boston All', 'BPDA All',unique(as.character(land_parcels$type)), unique(as.character(Energy_Parsed_Df$`Property Type`)))
)
}
})
output$scenario_table <- renderDataTable({
# generate bins based on input$bins from ui.R
the_data <- getData()
the_data <- the_data %>%
datatable() %>%
formatRound(columns=c('Kwh_potential', 'Cost_of_installation_gross'), digits=0)
}, options = list(scrollX = TRUE, order = list(list(4, 'desc'))))
### Leaflet map for energy tab
output$mymap <- renderLeaflet({
#browser()
the_data <- getData()
Boston_shape@data = data.frame(Boston_shape@data, the_data[match(Boston_shape@data$Property_Name, e$Property_Name),])
#rbPal <- colorRampPalette(c('green','red'))
# Boston_shape@data$score <- log(as.numeric(Boston_shape@data$Cost_of_installation_gross) / ((Boston_shape@data$Kwh_potential/Boston_shape@data$Total_Site_Energy_Kwh)* 100))
# Boston_shape@data$score <- rescale(Boston_shape@data$score, c(0, 100))
# Boston_shape@data <- subset(Boston_shape@data, select=-c(Pct_Gas, Pct_Electricity, Pct_Steam))
#
# ## Remove some outliers
# Boston_shape@data$score [which(Boston_shape@data$score == 0)] <- NA
# Boston_shape@data$score <- rescale(Boston_shape@data$score, c(0, 100))
# Boston_shape@data$height <-rescale(log(Boston_shape@data$Total_Site_Energy_Kwh), c(0,300))
# Boston_shape@data$color <- rbPal(10)[cut(as.numeric(Boston_shape@data$score),breaks = 10)]
Boston_shape <- sp.na.omit(Boston_shape, 'Kwh_potential')
#geojsonio::geojson_write(Boston_shape, file="www/data.geojson")
pal <- colorNumeric("viridis", NULL)
leaflet(Boston_shape) %>%
addTiles() %>%
addProviderTiles(providers$CartoDB.Positron) %>%
addPolygons(stroke = FALSE, smoothFactor = 0.3, fillOpacity = 1,
fillColor = ~pal(Kwh_potential)) %>%
addLegend(pal = pal, values = ~(Kwh_potential), opacity = 1.0)
})
### Scenario action button and compute
observeEvent(input$compute_button, {
if(input$land_building == "Boston Buildings"){
if('Boston All' %in% input$prop_types){
calculate_df <- Energy_Parsed_Df %>%
dplyr::select(Property_Name, `Property Type`, Address, Total_Site_Energy_Kwh,
sqft_available, sunlight_hours) %>%
mutate(Available_sqft_for_panels = sqft_available * (input$perc_roof_used/100),
Number_of_300watt_Panels = Available_sqft_for_panels / 20.67,
Kwh_potential = ((Number_of_300watt_Panels * 300)/1000) * sunlight_hours * 0.75,
Cost_of_installation_gross = Number_of_300watt_Panels * 300 * input$price_p_watt)
output$energy_requested <- renderInfoBox({
infoBox("Energy Coverage Requested", prettyNum((Total_energy_city_of_boston * (input$city_bost_perc/100)), big.mark = ','), icon = icon("flash"), color = "purple")
})
output$produced_by_selection <- renderInfoBox({
infoBox("Energy Produced", prettyNum(sum(calculate_df$Kwh_potential, na.rm = T), big.mark = ','), icon = icon("leaf"), color = "green")
})
output$percentage_covered <- renderInfoBox({
infoBox("Percent Covered", prettyNum(((sum(calculate_df$Kwh_potential, na.rm = T)/(Total_energy_city_of_boston * (input$city_bost_perc/100)))*100), big.mark = ','), icon = icon("signal"), color = "blue")
})
output$cost_of_implementation <- renderInfoBox({
infoBox("Cost of Implementation", prettyNum(sum(calculate_df$Cost_of_installation_gross, na.rm = T), big.mark = ','), icon = icon("money"), color = "orange")
})
} else {
calculate_df <- Energy_Parsed_Df %>%
dplyr::select(Property_Name, `Property Type`, Address, Total_Site_Energy_Kwh,
sqft_available, sunlight_hours) %>%
subset(`Property Type` %in% input$prop_types) %>%
mutate(Available_sqft_for_panels = sqft_available * (input$perc_roof_used/100),
Number_of_300watt_Panels = Available_sqft_for_panels / 20.67,
Kwh_potential = ((Number_of_300watt_Panels * 300)/1000) * sunlight_hours * 0.75,
Cost_of_installation_gross = Number_of_300watt_Panels * 300 * input$price_p_watt)
output$energy_requested <- renderInfoBox({
infoBox("Energy Coverage Requested", prettyNum((Total_energy_city_of_boston * (input$city_bost_perc/100)), big.mark = ','), icon = icon("flash"), color = "purple")
})
output$produced_by_selection <- renderInfoBox({
infoBox("Energy Produced", prettyNum(sum(calculate_df$Kwh_potential, na.rm = T), big.mark = ','), icon = icon("leaf"), color = "green")
})
output$percentage_covered <- renderInfoBox({
infoBox("Percent Covered", prettyNum(((sum(calculate_df$Kwh_potential, na.rm = T)/(Total_energy_city_of_boston * (input$city_bost_perc/100)))*100), big.mark = ','), icon = icon("signal"), color = "blue")
})
output$cost_of_implementation <- renderInfoBox({
infoBox("Cost of Implementation", prettyNum(sum(calculate_df$Cost_of_installation_gross, na.rm = T), big.mark = ','), icon = icon("money"), color = "orange")
})
}
} else if (input$land_building == "BPDA Owned Land"){
if('BPDA All' %in% input$prop_types){
calculate_df <- land_parsed_df %>%
dplyr::select(address, neighborhood, type, sunlight_hours, sqft_available) %>%
mutate(Available_sqft_for_panels = sqft_available * (input$perc_roof_used/100),
Number_of_300watt_Panels = Available_sqft_for_panels / 20.67,
Kwh_potential = ((Number_of_300watt_Panels * 300)/1000) * sunlight_hours * 0.75,
Cost_of_installation_gross = Number_of_300watt_Panels * 300 * input$price_p_watt)
output$energy_requested <- renderInfoBox({
infoBox("Energy Coverage Requested", prettyNum((Total_energy_city_of_boston * (input$city_bost_perc/100)), big.mark = ','), icon = icon("flash"), color = "purple")
})
output$produced_by_selection <- renderInfoBox({
infoBox("Energy Produced", prettyNum(sum(calculate_df$Kwh_potential, na.rm = T), big.mark = ','), icon = icon("leaf"), color = "green")
})
output$percentage_covered <- renderInfoBox({
infoBox("Percent Covered", prettyNum(((sum(calculate_df$Kwh_potential, na.rm = T)/(Total_energy_city_of_boston * (input$city_bost_perc/100)))*100), big.mark = ','), icon = icon("signal"), color = "blue")
})
output$cost_of_implementation <- renderInfoBox({
infoBox("Cost of Implementation", prettyNum(sum(calculate_df$Cost_of_installation_gross, na.rm = T), big.mark = ','), icon = icon("money"), color = "orange")
})
} else {
calculate_df <- land_parsed_df %>%
dplyr::select(address, neighborhood, type, sunlight_hours, sqft_available) %>%
subset(type %in% input$prop_types) %>%
mutate(Available_sqft_for_panels = sqft_available * (input$perc_roof_used/100),
Number_of_300watt_Panels = Available_sqft_for_panels / 20.67,
Kwh_potential = ((Number_of_300watt_Panels * 300)/1000) * sunlight_hours * 0.75,
Cost_of_installation_gross = Number_of_300watt_Panels * 300 * input$price_p_watt)
output$energy_requested <- renderInfoBox({
infoBox("Energy Coverage Requested", prettyNum((Total_energy_city_of_boston * (input$city_bost_perc/100)), big.mark = ','), icon = icon("flash"), color = "purple")
})
output$produced_by_selection <- renderInfoBox({
infoBox("Energy Produced", prettyNum(sum(calculate_df$Kwh_potential, na.rm = T), big.mark = ','), icon = icon("leaf"), color = "green")
})
output$percentage_covered <- renderInfoBox({
infoBox("Percent Covered", prettyNum(((sum(calculate_df$Kwh_potential, na.rm = T)/(Total_energy_city_of_boston * (input$city_bost_perc/100)))*100), big.mark = ','), icon = icon("signal"), color = "blue")
})
output$cost_of_implementation <- renderInfoBox({
infoBox("Cost of Implementation", prettyNum(sum(calculate_df$Cost_of_installation_gross, na.rm = T), big.mark = ','), icon = icon("money"), color = "orange")
})
}
} else if (input$land_building == 'Both'){
if('All' %in% input$prop_types){
calculate_df <- Energy_Parsed_Df %>%
dplyr::select(Property_Name, `Property Type`, Address, Total_Site_Energy_Kwh,
sqft_available, sunlight_hours) %>%
mutate(Available_sqft_for_panels = sqft_available * (input$perc_roof_used/100),
Number_of_300watt_Panels = Available_sqft_for_panels / 20.67,
Kwh_potential = ((Number_of_300watt_Panels * 300)/1000) * sunlight_hours * 0.75,
Cost_of_installation_gross = Number_of_300watt_Panels * 300 * input$price_p_watt)
bpda_calculate_df <- land_parsed_df %>%
dplyr::select(address, neighborhood, type, sunlight_hours, sqft_available) %>%
mutate(Available_sqft_for_panels = sqft_available * (input$perc_roof_used/100),
Number_of_300watt_Panels = Available_sqft_for_panels / 20.67,
Kwh_potential = ((Number_of_300watt_Panels * 300)/1000) * sunlight_hours * 0.75,
Cost_of_installation_gross = Number_of_300watt_Panels * 300 * input$price_p_watt)
output$energy_requested <- renderInfoBox({
infoBox("Energy Coverage Requested", prettyNum((Total_energy_city_of_boston * (input$city_bost_perc/100)), big.mark = ','), icon = icon("flash"), color = "purple")
})
output$produced_by_selection <- renderInfoBox({
infoBox("Energy Produced", prettyNum(sum(calculate_df$Kwh_potential, na.rm = T) + sum(bpda_calculate_df$Kwh_potential, na.rm = T), big.mark = ','), icon = icon("leaf"), color = "green")
})
output$percentage_covered <- renderInfoBox({
infoBox("Percent Covered", prettyNum((((sum(calculate_df$Kwh_potential, na.rm = T) + sum(bpda_calculate_df$Kwh_potential, na.rm = T))/(Total_energy_city_of_boston * (input$city_bost_perc/100)))*100), big.mark = ','), icon = icon("signal"), color = "blue")
})
output$cost_of_implementation <- renderInfoBox({
infoBox("Cost of Implementation", prettyNum((sum(calculate_df$Cost_of_installation_gross, na.rm = T) + sum(bpda_calculate_df$Cost_of_installation_gross, na.rm = T)), big.mark = ','), icon = icon("money"), color = "orange")
})
} else if ('BPDA All' %in% input$prop_types){
calculate_df <- Energy_Parsed_Df %>%
dplyr::select(Property_Name, `Property Type`, Address, Total_Site_Energy_Kwh,
sqft_available, sunlight_hours) %>%
subset(`Property Type` %in% input$prop_types) %>%
mutate(Available_sqft_for_panels = sqft_available * (input$perc_roof_used/100),
Number_of_300watt_Panels = Available_sqft_for_panels / 20.67,
Kwh_potential = ((Number_of_300watt_Panels * 300)/1000) * sunlight_hours * 0.75,
Cost_of_installation_gross = Number_of_300watt_Panels * 300 * input$price_p_watt)
bpda_calculate_df <- land_parsed_df %>%
dplyr::select(address, neighborhood, type, sunlight_hours, sqft_available) %>%
mutate(Available_sqft_for_panels = sqft_available * (input$perc_roof_used/100),
Number_of_300watt_Panels = Available_sqft_for_panels / 20.67,
Kwh_potential = ((Number_of_300watt_Panels * 300)/1000) * sunlight_hours * 0.75,
Cost_of_installation_gross = Number_of_300watt_Panels * 300 * input$price_p_watt)
output$energy_requested <- renderInfoBox({
infoBox("Energy Coverage Requested", prettyNum((Total_energy_city_of_boston * (input$city_bost_perc/100)),big.mark = ','), icon = icon("flash"), color = "purple")
})
output$produced_by_selection <- renderInfoBox({
infoBox("Energy Produced", prettyNum(sum(calculate_df$Kwh_potential, na.rm = T) + sum(bpda_calculate_df$Kwh_potential, na.rm = T), big.mark = ','), icon = icon("leaf"), color = "green")
})
output$percentage_covered <- renderInfoBox({
infoBox("Percent Covered", prettyNum((((sum(calculate_df$Kwh_potential, na.rm = T) + sum(bpda_calculate_df$Kwh_potential, na.rm = T))/(Total_energy_city_of_boston * (input$city_bost_perc/100)))*100), big.mark = ','), icon = icon("signal"), color = "blue")
})
output$cost_of_implementation <- renderInfoBox({
infoBox("Cost of Implementation", prettyNum(sum(calculate_df$Cost_of_installation_gross, na.rm = T) + sum(bpda_calculate_df$Cost_of_installation_gross, na.rm = T), big.mark = ','), icon = icon("money"), color = "orange")
})
} else if ('Boston All' %in% input$prop_types){
calculate_df <- Energy_Parsed_Df %>%
dplyr::select(Property_Name, `Property Type`, Address, Total_Site_Energy_Kwh,
sqft_available, sunlight_hours) %>%
mutate(Available_sqft_for_panels = sqft_available * (input$perc_roof_used/100),
Number_of_300watt_Panels = Available_sqft_for_panels / 20.67,
Kwh_potential = ((Number_of_300watt_Panels * 300)/1000) * sunlight_hours * 0.75,
Cost_of_installation_gross = Number_of_300watt_Panels * 300 * input$price_p_watt)
bpda_calculate_df <- land_parsed_df %>%
dplyr::select(address, neighborhood, type, sunlight_hours, sqft_available) %>%
subset(type %in% input$prop_types) %>%
mutate(Available_sqft_for_panels = sqft_available * (input$perc_roof_used/100),
Number_of_300watt_Panels = Available_sqft_for_panels / 20.67,
Kwh_potential = ((Number_of_300watt_Panels * 300)/1000) * sunlight_hours * 0.75,
Cost_of_installation_gross = Number_of_300watt_Panels * 300 * input$price_p_watt)
output$energy_requested <- renderInfoBox({
infoBox("Energy Coverage Requested", prettyNum((Total_energy_city_of_boston * (input$city_bost_perc/100)), big.mark = ','), icon = icon("flash"), color = "purple")
})
output$produced_by_selection <- renderInfoBox({
infoBox("Energy Produced", prettyNum(sum(calculate_df$Kwh_potential, na.rm = T) + sum(bpda_calculate_df$Kwh_potential, na.rm = T), big.mark = ','), icon = icon("leaf"), color = "green")
})
output$percentage_covered <- renderInfoBox({
infoBox("Percent Covered", prettyNum((((sum(calculate_df$Kwh_potential, na.rm = T) + sum(bpda_calculate_df$Kwh_potential, na.rm = T))/(Total_energy_city_of_boston * (input$city_bost_perc/100)))*100), big.mark = ','), icon = icon("signal"), color = "blue")
})
output$cost_of_implementation <- renderInfoBox({
infoBox("Cost of Implementation", prettyNum(sum(calculate_df$Cost_of_installation_gross, na.rm = T) + sum(bpda_calculate_df$Cost_of_installation_gross, na.rm = T), big.mark = ','), icon = icon("money"), color = "orange")
})
} else {
calculate_df <- Energy_Parsed_Df %>%
dplyr::select(Property_Name, `Property Type`, Address, Total_Site_Energy_Kwh,
sqft_available, sunlight_hours) %>%
subset(`Property Type` %in% input$prop_types) %>%
mutate(Available_sqft_for_panels = sqft_available * (input$perc_roof_used/100),
Number_of_300watt_Panels = Available_sqft_for_panels / 20.67,
Kwh_potential = ((Number_of_300watt_Panels * 300)/1000) * sunlight_hours * 0.75,
Cost_of_installation_gross = Number_of_300watt_Panels * 300 * input$price_p_watt)
bpda_calculate_df <- land_parsed_df %>%
dplyr::select(address, neighborhood, type, sunlight_hours, sqft_available) %>%
subset(type %in% input$prop_types) %>%
mutate(Available_sqft_for_panels = sqft_available * (input$perc_roof_used/100),
Number_of_300watt_Panels = Available_sqft_for_panels / 20.67,
Kwh_potential = ((Number_of_300watt_Panels * 300)/1000) * sunlight_hours * 0.75,
Cost_of_installation_gross = Number_of_300watt_Panels * 300 * input$price_p_watt)
output$energy_requested <- renderInfoBox({
infoBox("Energy Coverage Requested", prettyNum((Total_energy_city_of_boston * (input$city_bost_perc/100)), big.mark = ','), icon = icon("flash"), color = "purple")
})
output$produced_by_selection <- renderInfoBox({
infoBox("Energy Produced", prettyNum(sum(calculate_df$Kwh_potential, na.rm = T) + sum(bpda_calculate_df$Kwh_potential, na.rm = T), big.mark = ','), icon = icon("leaf"), color = "green")
})
output$percentage_covered <- renderInfoBox({
infoBox("Percent Covered", prettyNum((((sum(calculate_df$Kwh_potential, na.rm = T) + sum(bpda_calculate_df$Kwh_potential, na.rm = T))/(Total_energy_city_of_boston * (input$city_bost_perc/100)))*100), big.mark = ','), icon = icon("signal"), color = "blue")
})
output$cost_of_implementation <- renderInfoBox({
infoBox("Cost of Implementation", prettyNum(sum(calculate_df$Cost_of_installation_gross, na.rm = T) + sum(bpda_calculate_df$Cost_of_installation_gross, na.rm = T), big.mark = ','), icon = icon("money"), color = "orange")
})
}
}
output$scenario_table <- renderDataTable({
calculate_df
}, options = list(scrollX = TRUE, order = list(list(4, 'desc'))))
})
})