-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathserver.R
More file actions
65 lines (49 loc) · 1.76 KB
/
Copy pathserver.R
File metadata and controls
65 lines (49 loc) · 1.76 KB
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
#OUR POLLUTION DATA
library(shiny)
library(leaflet)
library(htmltools)
shinyServer(
function(input, output){
# variable date stores the slide selected value
output$date <- renderText(input$slide)
output$map <- renderLeaflet({
leaflet() %>%
addTiles(
urlTemplate = "//{s}.tiles.mapbox.com/v3/jcheng.map-5ebohr46/{z}/{x}/{y}.png",
attribution = 'Maps by <a href="http://www.mapbox.com/">Mapbox</a>'
) %>%
setView(lng = -93.85, lat = 37.45, zoom = 4)
})
# NOT NEEDED ------------------------------------
# This observer is responsible for maintaining the circles and legend,
# according to the variables the user has chosen to map to color and size.
observe({
colorBy <- input$color
sizeBy <- input$size
timeBy <- input$slide
zipdata <- switch(
timeBy-1999,
pollution.2000,
pollution.2001,
pollution.2002,
pollution.2003,
pollution.2004,
pollution.2005,
pollution.2006,
pollution.2007,
pollution.2008,
pollution.2009,
pollution.2010
)
colorData <- zipdata[[colorBy]]
pal <- colorBin("Spectral", colorData, 7, pretty = FALSE)
radius <- zipdata[[sizeBy]] / max(zipdata[[sizeBy]]) * 300000
leafletProxy("map", data = zipdata) %>%
clearShapes() %>%
addCircles(~Longitude, ~Latitude, radius=radius,
stroke=FALSE, fillOpacity=0.4, fillColor=pal(colorData)) %>%
addLegend("bottomleft", pal=pal, values=colorData, title=colorBy,
layerId="colorLegend")
})
}
)