Browse Source

More robust attribute update

Petra Lamborn 3 years ago
parent
commit
55d623609d
2 changed files with 31 additions and 16 deletions
  1. 17
    15
      viz/app.R
  2. 14
    1
      viz/extras.R

+ 17
- 15
viz/app.R View File

@@ -82,6 +82,7 @@ ui <- fluidPage(
82 82
 # Define server logic
83 83
 server <- function(input, output) {
84 84
   sel.SA2.code <- reactiveVal(0)
85
+  attribupdate <- FALSE
85 86
   output$map <- renderLeaflet({
86 87
     leaf <- leaflet(shpf, options = leafletOptions(minZoom = 3, maxZoom = 13)) %>% 
87 88
       addPolygons(color="#000", opacity = 1, weight=1,
@@ -191,22 +192,23 @@ server <- function(input, output) {
191 192
     sel.SA2.code(ifelse(sel.SA2.code() == codetmp, 0, codetmp))
192 193
     updateMap()
193 194
   })
195
+  observeEvent(input$map_zoom, once=TRUE, {
196
+    if (!attribupdate) {
197
+      print(attribupdate)
198
+      shinyjs::html(selector=".leaflet-control-attribution.leaflet-control",
199
+                    html = attribhtml)
200
+      attribupdate <<- TRUE
201
+    }
202
+  })
194 203
   observeEvent(input$map_shape_mouseover, once=TRUE,{
195
-    shinyjs::html(selector=".leaflet-control-attribution.leaflet-control",
196
-                  html = '
197
-<a href="http://leafletjs.com" 
198
-title="A JS library for interactive maps">Leaflet</a> | <a 
199
-href="https://datafinder.stats.govt.nz/data/category/census/2018/commuter-view/"
200
-title="Source data">
201
-StatsNZ</a> | <a href="https://petras.space/page/cv/" title="Hire me!">
202
-Petra Lamborn</a> | Numbers subject to <a
203
-href="http://archive.stats.govt.nz/about_us/legisln-policies-protocols/
204
-confidentiality-of-info-supplied-to-snz/safeguarding-confidentiality.aspx"
205
-title="A method of preserving confidentiality and anonymity">
206
-random rounding</a>
207
-                  '
208
-                )
209
-               })
204
+    # Backup
205
+    if (!attribupdate) {
206
+      print(attribupdate)
207
+      shinyjs::html(selector=".leaflet-control-attribution.leaflet-control",
208
+                    html = attribhtml)
209
+      attribupdate <<- TRUE
210
+    }
211
+  })
210 212
   observeEvent(input$radioinout, ignoreInit = TRUE, {
211 213
     updateMap()
212 214
   })

+ 14
- 1
viz/extras.R View File

@@ -51,4 +51,17 @@ html, body {
51 51
   margin-right: 0px !important;
52 52
   margin-bottom: 0px !important;
53 53
 }
54
-"
54
+"
55
+
56
+attribhtml <- '
57
+<a href="http://leafletjs.com" 
58
+title="A JS library for interactive maps">Leaflet</a> | <a 
59
+href="https://datafinder.stats.govt.nz/data/category/census/2018/commuter-view/"
60
+title="Source data">
61
+StatsNZ</a> | <a href="https://petras.space/page/cv/" title="Hire me!">
62
+Petra Lamborn</a> | Numbers subject to <a
63
+href="http://archive.stats.govt.nz/about_us/legisln-policies-protocols/
64
+confidentiality-of-info-supplied-to-snz/safeguarding-confidentiality.aspx"
65
+title="A method of preserving confidentiality and anonymity">
66
+random rounding</a>
67
+'