This repository has been archived by the owner on Feb 10, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.R
119 lines (91 loc) · 3.55 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
library(shiny)
library(tidyverse)
library(jsonlite)
# Data Handling
Yelp_SLO <- as.data.frame(fromJSON("data/businesses_SLO.json")) %>%
filter(!businesses.is_closed)
categories <- Yelp_SLO %>%
select(businesses.id, businesses.categories) %>%
unnest()
categories_matrix <- categories %>%
spread(key = title, value = alias)
categories_map <- data.frame(alias = unique(categories$alias), title = unique(categories$title))
shinyServer(function(input, output) {
# method for printing the main map
output$map <- renderLeaflet({
# main map features
Yelp_map <- leaflet(data = Yelp_SLO) %>%
setView(Yelp_SLO$region.center.longitude[1], Yelp_SLO$region.center.latitude[1], zoom = 12) %>%
addEasyButton(easyButton(
icon="fa-crosshairs", title="Locate Me",
onClick=JS("function(btn, map){ map.locate({setView: true}); }"))) %>%
addTiles()
})
check_category <- function(id, category) {
!categories_matrix %>%
filter(businesses.id == id) %>%
select(category) %>%
is.na()
}
# update data according to input parameters
update_data <- function() {
Yelp_update <- Yelp_SLO
# filter by price
if(input$price != 0) {
Yelp_update <- Yelp_update %>%
filter(businesses.price == input$price)
}
# filter by category
if(input$category != "All") {
Yelp_update <- Yelp_update %>%
filter(sapply(businesses.id, check_category, category = input$category))
}
# filter by review count / review number
Yelp_update %>%
filter(businesses.review_count >= input$review_counts[1] & businesses.review_count <= input$review_counts[2]) %>%
filter(businesses.rating >= input$review_number[1] & businesses.rating <= input$review_number[2])
}
updatePopup <- function(){
popupContent <- "test"
}
# change markers / clustering mode / heatmap
observe({
proxy <- leafletProxy("map", data = update_data()) %>%
clearMarkerClusters() %>%
clearMarkers()
popupContent <- ~paste0('<font face = "arial">',"<b><a href='",businesses.url,"'>", businesses.name, "</a></b><br>",
address, "<br>",
'<b><font color="green">Price: </b>', businesses.price, "</font><br>",
'<b><font color="red">Rating: </b>', businesses.rating, '</font><br><br>',
'<img src="', businesses.image_url,'"width="200" height="200"></font>'
)
clearWebGLHeatmap(proxy)
# conditional pin cluster
if(input$cluster) {
proxy %>% addMarkers(~longitude, ~latitude, popup = popupContent, clusterOptions = markerClusterOptions()
, icon = list(iconUrl = "img/red-map-marker.png", iconSize = c(25, 25)))
}
else if(input$heatmap){
proxy %>%
addWebGLHeatmap(lng=~longitude, lat=~latitude, size = 1000)
} else {
proxy %>% addMarkers(~longitude, ~latitude, popup = popupContent, icon = list(iconUrl = "img/red-map-marker.png", iconSize = c(25, 25)))
}
})
# Output Data Table of Selected Businesses
output$table <- renderDataTable({
update_data() %>%
select(
Name = businesses.name,
"Review Count" = businesses.review_count,
Rating = businesses.rating,
Price = businesses.price,
Phone = businesses.display_phone,
"Street Address" = address
)
})
# Render method for about pages
output$about <- renderUI({
includeHTML("YelpReport.html")
})
})