Browse Source

Working, but slow implementation of dhb boundaries

Note layer issues!
Petra Lamborn 4 years ago
parent
commit
3d083fa472
4 changed files with 37 additions and 5 deletions
  1. 9
    0
      GeoProcessing.R
  2. 28
    5
      MedicalCentres/app.R
  3. BIN
      MedicalCentres/dhb2015.rds
  4. 0
    0
      statsnzdistrict-health-board-2015-SHP.zip

+ 9
- 0
GeoProcessing.R View File

1
+td <- tempdir()
2
+
3
+unzip("statsnzdistrict-health-board-2015-SHP.zip", exdir = td)
4
+dhb2015 <- readOGR(td, layer="district-health-board-2015")
5
+dhbsub <- subset(dhb2015, dhb2015$DHB2015_Co != "99")
6
+#dhbsub <- gSimplify(dhbsub, tol = 0.01, topologyPreserve = TRUE)
7
+#
8
+#saveRDS(dhbsub, "MedicalCentres/dhb2015.rds")
9
+saveRDS(dhb2015, "MedicalCentres/dhb2015.rds")

+ 28
- 5
MedicalCentres/app.R View File

4
 library(dplyr)
4
 library(dplyr)
5
 library(shinyWidgets)
5
 library(shinyWidgets)
6
 library(htmltools)
6
 library(htmltools)
7
+library(rgdal)
8
+library(rgeos)
9
+library(ggfortify)
7
 
10
 
8
 leafcols <- c("blue", "red", "darkred", "lightred",
11
 leafcols <- c("blue", "red", "darkred", "lightred",
9
           "orange", "beige", "green", "darkgreen",
12
           "orange", "beige", "green", "darkgreen",
33
     sdf
36
     sdf
34
 }
37
 }
35
 
38
 
39
+dhb2015 <- readRDS("dhb2015.rds")
36
 
40
 
37
 popups <- function(data) {
41
 popups <- function(data) {
38
 sprintf("<strong>%s</strong><br/>%s<br/>DHB: %s<br/>%s",
42
 sprintf("<strong>%s</strong><br/>%s<br/>DHB: %s<br/>%s",
90
 
94
 
91
 server <- function(input, output, session) {
95
 server <- function(input, output, session) {
92
     output$medmap <- renderLeaflet({
96
     output$medmap <- renderLeaflet({
93
-        gl <- leaflet(Geo2017)
97
+        gl <- leaflet(Geo2017) %>%
98
+          addMapPane("polygons", zIndex = 420) %>%
99
+          addMapPane("markers", zIndex = 430)
94
         gl <- addTiles(gl)
100
         gl <- addTiles(gl)
95
         gl <- addCircleMarkers(gl, lng = Geo2017$lon,
101
         gl <- addCircleMarkers(gl, lng = Geo2017$lon,
96
                    lat = Geo2017$lat,
102
                    lat = Geo2017$lat,
97
                    popup = popups(Geo2017),
103
                    popup = popups(Geo2017),
98
-                   col= "blue")
104
+                   col= "blue",
105
+                   #pathOptions(pane = "markers")
106
+                   )
99
         gl
107
         gl
100
     })
108
     })
101
 
109
 
111
                      lat = Geo2017$lat,
119
                      lat = Geo2017$lat,
112
                      popup = popups(Geo2017),
120
                      popup = popups(Geo2017),
113
                      # color = snargcols[as.character(Geo2017$dhb_name)]
121
                      # color = snargcols[as.character(Geo2017$dhb_name)]
114
-                     col = snargcol(Geo2017$Snargle)
122
+                     col = snargcol(Geo2017$Snargle),
123
+                     #pathOptions(pane = "markers")
115
                      )
124
                      )
116
       } else if (input$selcol == "DHB") {
125
       } else if (input$selcol == "DHB") {
117
           gl <- addCircleMarkers(gl, lng = Geo2017$lon,
126
           gl <- addCircleMarkers(gl, lng = Geo2017$lon,
118
                      lat = Geo2017$lat,
127
                      lat = Geo2017$lat,
119
                      popup = popups(Geo2017),
128
                      popup = popups(Geo2017),
120
                      # color = dhbcols[Geo2017$dhb_name]
129
                      # color = dhbcols[Geo2017$dhb_name]
121
-                     col = dhbcol(Geo2017$dhb_name)
130
+                     col = dhbcol(Geo2017$dhb_name),
131
+                     #pathOptions(pane = "markers")
122
                      )
132
                      )
123
       } else {
133
       } else {
124
           gl <- addCircleMarkers(gl, lng = Geo2017$lon,
134
           gl <- addCircleMarkers(gl, lng = Geo2017$lon,
125
                      lat = Geo2017$lat,
135
                      lat = Geo2017$lat,
126
                      popup = popups(Geo2017),
136
                      popup = popups(Geo2017),
127
-                     col= "blue")
137
+                     col= "blue",
138
+                     #pathOptions(pane = "markers")
139
+                     )
128
       }
140
       }
129
     })
141
     })
130
 
142
 
143
                                          zoom = 13)
155
                                          zoom = 13)
144
       }
156
       }
145
     })
157
     })
158
+    observeEvent(input$dhboverlay, {
159
+      if (input$dhboverlay) {
160
+        leafletProxy("medmap") %>% addPolygons(data = dhbsub, fill = FALSE,
161
+                                               color = "#000000",
162
+                                               weight = 2,
163
+                                               #pathOptions(pane = "polygons")
164
+                                               )
165
+      } else {
166
+        leafletProxy("medmap") %>% clearShapes()
167
+      }
168
+    })
146
 
169
 
147
 }
170
 }
148
 
171
 

BIN
MedicalCentres/dhb2015.rds View File


MedicalCentres/statsnzdistrict-health-board-2015-SHP.zip → statsnzdistrict-health-board-2015-SHP.zip View File