-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathserver.R
46 lines (44 loc) · 1.78 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
list.of.packages <- c("choroplethr", "choroplethrMaps", "choroplethrAdmin1", "zipcode")
new.packages <- list.of.packages[!(list.of.packages %in% installed.packages()[,"Package"])]
if(length(new.packages)) install.packages(new.packages)
library(choroplethr)
library(choroplethrMaps)
library(choroplethrAdmin1)
library(zipcode)
shinyServer(
function(input, output)
{
observe({
num_buckets = input$num_buckets
if (input$map_name == "USA State") {
output$map <- renderPlot({
data(df_pop_state)
zoom = if(length(input$usa_zoom) == 0) NULL else input$usa_zoom
state_choropleth(df_pop_state, "2012 State Population Estimates", "Population", num_buckets, zoom)
})
} else if (input$map_name == "USA County") {
output$map <- renderPlot({
data(df_pop_county)
zoom = if(length(input$usa_zoom) == 0) NULL else input$usa_zoom
county_choropleth(df_pop_county, "2012 County Population Estimates", "Population", num_buckets, zoom)
})
} else if (input$map_name == "USA ZIP") {
data(df_pop_zip)
zoom = if(length(input$usa_zoom) == 0) NULL else input$usa_zoom
output$map <- renderPlot({
zip_map(df_pop_zip, "2012 ZCTA (ZIP Code) Population Estimates", "Population", num_buckets, zoom)
})
} else if (input$map_name == "Country") {
output$map <- renderPlot({
zoom = if(length(input$country_zoom) == 0) NULL else input$country_zoom
data(df_pop_country)
country_choropleth(df_pop_country, "2012 Country Population Estimates", "Population", num_buckets, zoom)
})
} else if (input$map_name == "Admin1") {
output$map <- renderPlot({
admin1_map(input$admin1_zoom)
})
}
})
}
)