-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.R
100 lines (75 loc) · 3.5 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
library("shiny")
library("leaflet")
library("DT")
library("dplyr")
shinyServer(function(input, output, session) {
data.selected <- reactive({
#Filter to map year
map.data <- data %>% filter(Year == input$map.year)
if(input$filter.verified == TRUE) {
map.data <- map.data %>%
filter(status=="Verified Location" | status =="Google Verified Location")
}
if(input$map.am.feature == "(G)" && input$map.year != 1980) {
map.data <- map.data %>% filter(grepl("(G)", map.data$amenityfeatures, fixed = TRUE))
} else if (input$map.am.feature == "(G)" && input$map.year == 1980) {
map.data <- map.data %>% filter(grepl("(L)", map.data$amenityfeatures, fixed = TRUE))
} else if(input$map.am.feature != "Show all") {
map.data <- map.data %>%
filter(grepl(input$map.am.feature, map.data$amenityfeatures, fixed = TRUE))
}
if(input$map.type == "Hotel Bar") {
map.data <- map.data %>%
filter(grepl("Bars/Clubs", map.data$type, fixed = TRUE) & grepl("Hotel", map.data$type, fixed = TRUE))
} else if(input$map.type != "Show all") {
map.data <- map.data %>%
filter(grepl(input$map.type, map.data$type, fixed = TRUE))
}
if (all(input$map.city != "All locations")) {
map.data <- map.data %>%
filter(state == input$map.city)
}
map.data
})
bib_for_table <- reactive({
data.selected() %>%
arrange(state, city, Year) %>%
select(title, Year, description, streetaddress, city, state, amenityfeatures, type, status)
})
bib_for_map <- reactive({
data.selected() %>%
arrange(state, city, Year) %>%
select(title, Year, description, streetaddress, city, state, amenityfeatures, type, status, lat, lon)
})
output$spaces_map <- renderLeaflet({
leaflet() %>%
addTiles(options = tileOptions(minZoom = 3)) %>%
setView(lat = 37.45, lng = -93.85, zoom = 3) %>%
setMaxBounds(-132.068706, 14.670437, -69.999931, 73.278273)
})
output$spaces.table <- DT::renderDataTable({bib_for_table()},
rownames = FALSE,
class = "display compact",
style = "bootstrap",
options = list(pageLength=50))
output$num.locations <- renderText({
map.data <- data.selected()
location.count <- length(map.data$title)
paste("In ", input$map.year, " there are ", location.count, " locations. Scroll through each one in the table below." )
})
observe({
df <- bib_for_map()
leafletProxy("spaces_map", session) %>%
clearMarkerClusters() %>%
clearPopups()
leafletProxy("spaces_map", data = df) %>%
addMarkers(lng = ~lon, lat = ~lat, popup= paste("<b>Location Name:</b>", df$title, "<br><b>Description: </b>", df$description,"<br><b>Amenities: </b>", df$amenityfeatures, "<br><b>Type: </b>", df$type, "<br><b>Status: </b>", df$status), clusterOptions = markerClusterOptions(maxClusterRadius = 43))
}) # End Observe
observeEvent(input$reset_button, {
updateSelectInput(session, "map.city", selected = "All locations")
updateSelectInput(session, "map.am.feature", selected = "Show all")
updateSelectInput(session, "map.type", selected = "Show all")
updateCheckboxInput(session, "filter.verified", value = FALSE)
updateSliderTextInput(session, "map.year", selected=1965)
})
}) # end ShinyServer function