Ver código fonte

Better reloading

Petra Lamborn 4 anos atrás
pai
commit
c5b28f87c7
1 arquivos alterados com 29 adições e 20 exclusões
  1. 29
    20
      MedicalCentres/app.R

+ 29
- 20
MedicalCentres/app.R Ver arquivo

@@ -100,26 +100,10 @@ server <- function(input, output) {
100 100
     output$medmap <- renderLeaflet({
101 101
         gl <- leaflet(Geo2017)
102 102
         gl <- addTiles(gl)
103
-        if (input$selcol == "Snargleflagen") {
104
-            gl <- addCircleMarkers(gl, lng = Geo2017$lon,
105
-                       lat = Geo2017$lat,
106
-                       popup = popups(Geo2017),
107
-                       # color = snargcols[as.character(Geo2017$dhb_name)]
108
-                       col = snargcol(Geo2017$Snargle)
109
-                       )
110
-        } else if (input$selcol == "DHB") {
111
-            gl <- addCircleMarkers(gl, lng = Geo2017$lon,
112
-                       lat = Geo2017$lat,
113
-                       popup = popups(Geo2017),
114
-                       # color = dhbcols[Geo2017$dhb_name]
115
-                       col = dhbcol(Geo2017$dhb_name)
116
-                       )
117
-        } else {
118
-            gl <- addCircleMarkers(gl, lng = Geo2017$lon,
119
-                       lat = Geo2017$lat,
120
-                       popup = popups(Geo2017),
121
-                       col= "blue")
122
-        }
103
+        gl <- addCircleMarkers(gl, lng = Geo2017$lon,
104
+                   lat = Geo2017$lat,
105
+                   popup = popups(Geo2017),
106
+                   col= "blue")
123 107
         gl
124 108
     })
125 109
 
@@ -127,6 +111,31 @@ server <- function(input, output) {
127 111
       toggleDropdownButton("ddown")
128 112
     })
129 113
 
114
+    observeEvent(input$selcol, {
115
+      gl <- leafletProxy("medmap") %>%
116
+          clearMarkers()
117
+      if (input$selcol == "Snargleflagen") {
118
+          gl <- addCircleMarkers(gl, lng = Geo2017$lon,
119
+                     lat = Geo2017$lat,
120
+                     popup = popups(Geo2017),
121
+                     # color = snargcols[as.character(Geo2017$dhb_name)]
122
+                     col = snargcol(Geo2017$Snargle)
123
+                     )
124
+      } else if (input$selcol == "DHB") {
125
+          gl <- addCircleMarkers(gl, lng = Geo2017$lon,
126
+                     lat = Geo2017$lat,
127
+                     popup = popups(Geo2017),
128
+                     # color = dhbcols[Geo2017$dhb_name]
129
+                     col = dhbcol(Geo2017$dhb_name)
130
+                     )
131
+      } else {
132
+          gl <- addCircleMarkers(gl, lng = Geo2017$lon,
133
+                     lat = Geo2017$lat,
134
+                     popup = popups(Geo2017),
135
+                     col= "blue")
136
+      }
137
+    })
138
+
130 139
 }
131 140
 
132 141
 # Run the application