-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.R
79 lines (56 loc) · 2.79 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
#setwd("H:/USER/JGenser/Pot Holes/Program")
library(leaflet)
library(shiny)
library(colorRamps)
##import cleaned pothole data
df = read.csv("mappingData.csv",header=T, sep =",")
many = read.csv("manyFills.csv", header=T, sep=",")
##if lag is negative, set to 0
df$lag[which(df$lag == -1 )] <- 0
##if lag is greater than 3 weeks, set to 22 days
df$lag[which(df$lag > 21 )] <- 22
##create color palate
#pal <- colorBin("RdYlGn", sort(df$lag, decreasing=F))
pal <- colorBin(matlab.like(length(df$lag)), df$lag)
cznData = subset(df, grepl("Citizen", Source))
ctyData = subset(df, grepl("City", Source))
callData = subset(df, grepl("Constituent", Source))
selfData = subset(df, grepl("Self", Source))
empData = subset(df, grepl("Employee", Source))
cambData = df[df$Source == "",]
ui = fluidPage(
leafletOutput("map", height = 720, width = 1280)
)
server <- function(input, output) {
##render map and add circles
output$map <- renderLeaflet ({
leaflet(df) %>%
setView(-71.083, 42.353, 13) %>%
addProviderTiles("Stamen.TonerLite", options = providerTileOptions(noWrap=T)) %>%
addLegend("bottomright", pal = pal, values = df$lag, title ="Days Until Repair" , opacity = 1) %>%
addCircles(data = cznData, radius=35, stroke=FALSE, fillColor = pal(cznData$lag),
fillOpacity = 0.75,
group = "Citizens Connect App") %>%
addCircles(data = ctyData, radius=35, stroke=FALSE, fillColor = pal(ctyData$lag),
fillOpacity = 0.75,
group = "City Workers App") %>%
addCircles(data = callData, radius=35, stroke=FALSE, fillColor = pal(callData$lag),
fillOpacity = 0.75,
group = "Constituent Call-in") %>%
addCircles(data = selfData, radius=35, stroke=FALSE, fillColor = pal(selfData$lag),
fillOpacity = 0.75,
group = "Self Service") %>%
addCircles(data = empData, radius=35, stroke=FALSE, fillColor = pal(empData$lag),
fillOpacity = 0.75,
group = "Employee Generated") %>%
addCircles(data = cambData, radius=35, stroke=FALSE, fillColor = pal(df$lag),
fillOpacity = 0.75,
group = "Cambridge (Source NA)") %>%
addCircles(data = many, radius = 35, stroke=FALSE, fillColor = "black", fillOpacity = 0.8,
group = "Repeat Offender") %>%
addLayersControl(overlayGroups =
c("Citizens Connect App", "City Workers App", "Constituent Call-in", "Self Service", "Employee Generated", "Cambridge (Source NA)", "Repeat Offender"),
options = layersControlOptions(collapsed=F)) %>% hideGroup(c("City Workers App", "Constituent Call-in", "Self Service", "Employee Generated", "Cambridge (Source NA)", "Repeat Offender"))
})
}
shinyApp(ui = ui, server = server)