-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.R
executable file
·104 lines (75 loc) · 2.89 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
#
# This is the server logic of a Shiny web application. You can run the
# application by clicking 'Run App' above.
#
# Find out more about building applications with Shiny here:
#
# http://shiny.rstudio.com/
#
library(shiny)
# #install rgdl & Leaflet library for polygons
#install.packages("magrittr")
library(magrittr)
#install.packages("rgdal")
library(rgdal)
#install.packages("leaflet")
library(leaflet)
#install.packages("dplyr")
library(dplyr)
#install.packages("colorRamps")
library(colorRamps)
#install.packages("graphics")
library(graphics)
#install.packages("RColorBrewer")
library(RColorBrewer)
#install.packages("foreign")
library(foreign)
#install.packages("maptools")
library(maptools)
#install.packages("ggplot2")
library(ggplot2)
##load shape file
SLA <- readOGR(dsn= "/Users/robertj9/L.GitHub/L.uncert_spatial_map/Qld.shape_files",
layer = "SLA_QLD_06", verbose = FALSE)
#load file with estimates
data <- read.csv("/Users/robertj9/L.Github/L.uncert_spatial_map/est.datafile.10feb2016.csv")
#add SIR values to data file?
SLA$estimate <- data$est
## add risk to data file - this isn't necessary because when using the palette colorbin, x must be numeric and cannot be character. Althought I will leave it in in case I want to use a categorical palett in the future. A categorical palette may also be easier for defining the risk cut offs, rather than having to specify the bin cut offs.
data <- data %>%
mutate(Risk = ifelse(est < 0.769,
yes = "Very Low",
no = ifelse(est < 0.909,
yes = "Low",
no = ifelse(est < 1.1,
yes = "Average",
no = ifelse(est <1.3,
yes = "High",
no = ifelse(est >1.31,
yes = "Very High",
no = "Very High"))))))
##SLA$estimate <- data$est
SLA$ci.u <- data$ci.u
SLA$ci.l <- data$ci.l
SLA$ci.length <- data$ci.length
SLA$Risk <- data$Risk
#Legend labels
legend.lab <- c("Very High"," ", "High"," ", "Average", " ", "Low", " ", "Very Low")
#create a colour palette _______________________________________
pal1 <- colorBin( c("#CCCC00","#FFFFFF", "#993399"), SLA$estimate, bins = c( 0.0, 0.769, 0.839, 0.909, 1.1, 1.2, 1.3, 2.06), pretty = FALSE)
#pal2 <- colorQuantile("Blues", SLA$estimate, n=5)
#Draw Map
my.map <- leaflet(SLA) %>%
addPolygons(
stroke = FALSE, fillOpacity = 1, smoothFactor = 0.2,
color = ~pal1(SLA$estimate)
) %>%
addLegend("bottomleft", values = SLA$estimate, title = "Spatial Health Map", colors= c( "#993399", "#B970B6", "#D6A9D3", "#F2E2F0", "#FFFFFF","#FBF7E1", "#EFE8A4", "#E0DA66", "#CCCC00" ), labels = legend.lab, opacity = 1)
my.map
#----
shinyServer(
function(input, output) {
my.map = my.map
output$my.map <- renderLeaflet(my.map)
}
)