Browse Source

Add information panel

Petra Lamborn 3 years ago
parent
commit
b308ba7105
2 changed files with 102 additions and 8 deletions
  1. 10
    7
      viz/app.R
  2. 92
    1
      viz/extras.R

+ 10
- 7
viz/app.R View File

@@ -39,6 +39,7 @@ ui <- fluidPage(
39 39
   tags$style(type = "text/css", extracss),
40 40
   leafletOutput("map"),
41 41
   absolutePanel(top = 10, right = 10, id="mapcontrol",
42
+                div(
42 43
                 radioButtons("radioinout", label="Show commuters who",
43 44
                              choiceNames = list(
44 45
                                HTML("<p>Commute <b>from</b> selected area</p>"),
@@ -60,14 +61,14 @@ ui <- fluidPage(
60 61
                              ),
61 62
                              inline = FALSE),
62 63
                 div(id="locinfo",
63
-                    htmlOutput("lochtml"))),
64
+                    htmlOutput("lochtml")))),
64 65
   absolutePanel(top = 25, right = 10, id="control2",
65 66
                 materialSwitch("controlswitch", value=TRUE, right=TRUE,
66 67
                                inline=TRUE, status="info")),
67 68
   absolutePanel(bottom = 30, left = 10, id="loading",
68 69
                 p("Loading...")),
69 70
   absolutePanel(bottom=26, right=10, left=10, top=10, id="infopanel",
70
-                p("Test")),
71
+                infotext),
71 72
   absolutePanel(bottom=10, right=10, id="infobuttoncontainer",
72 73
     prettyToggle("mapinfobutton", label_on = "Info",
73 74
                  label_off = "Info", icon_on=icon("times"),
@@ -181,6 +182,7 @@ server <- function(input, output) {
181 182
                          time = 1)
182 183
   }
183 184
   observeEvent(input$map_click, ignoreInit = TRUE, {
185
+    cursel <- sel.SA2.code()
184 186
     p <- input$map_click
185 187
     pdat <- data.frame(Longitude = p$lng,
186 188
                       Latitude =p$lat)
@@ -189,12 +191,14 @@ server <- function(input, output) {
189 191
     ppoly <- over(pdat, shpf)
190 192
     codetmp <- as.numeric(as.character(ppoly[1,"SA22018_V1"]))
191 193
     codetmp <- ifelse(is.na(codetmp), 0, codetmp)
192
-    sel.SA2.code(ifelse(sel.SA2.code() == codetmp, 0, codetmp))
193
-    updateMap()
194
+    newsl <- ifelse(sel.SA2.code() == codetmp, 0, codetmp)
195
+    if (newsl != cursel) {
196
+      sel.SA2.code(newsl)
197
+      updateMap()
198
+    }
194 199
   })
195 200
   observeEvent(input$map_zoom, once=TRUE, {
196 201
     if (!attribupdate) {
197
-      print(attribupdate)
198 202
       shinyjs::html(selector=".leaflet-control-attribution.leaflet-control",
199 203
                     html = attribhtml)
200 204
       attribupdate <<- TRUE
@@ -203,7 +207,6 @@ server <- function(input, output) {
203 207
   observeEvent(input$map_shape_mouseover, once=TRUE,{
204 208
     # Backup
205 209
     if (!attribupdate) {
206
-      print(attribupdate)
207 210
       shinyjs::html(selector=".leaflet-control-attribution.leaflet-control",
208 211
                     html = attribhtml)
209 212
       attribupdate <<- TRUE
@@ -224,7 +227,7 @@ server <- function(input, output) {
224 227
   })
225 228
   observeEvent(input$mapinfobutton, ignoreInit = TRUE, {
226 229
     shinyjs::toggleElement("infopanel", anim=TRUE,
227
-                           time = 1)
230
+                           time = 0.5)
228 231
   })
229 232
   output$lochtml <- renderUI({
230 233
     seled <- sel.SA2.code()

+ 92
- 1
viz/extras.R View File

@@ -27,9 +27,13 @@ html, body {
27 27
   padding: 6px 8px;
28 28
   font: 14px/16px Arial, Helvetica, sans-serif;
29 29
 }
30
+#mapcontrol, #control2 {
31
+  z-index: 1000;
32
+}
30 33
 #infopanel {
31 34
   display: none;
32
-  padding: 30px;
35
+  background-color: rgba(255, 255, 255, 0.9);
36
+  padding: 10px;
33 37
   z-index: 1001;
34 38
 }
35 39
 #lochtml ul {
@@ -51,6 +55,39 @@ html, body {
51 55
   margin-right: 0px !important;
52 56
   margin-bottom: 0px !important;
53 57
 }
58
+h3 {
59
+  margin-top: 5px;
60
+  margin-bottom: 5px;
61
+}
62
+.overflowable {
63
+  max-height: 100%;
64
+  overflow: auto;
65
+  -ms-overflow-style: none;  /* IE and Edge */
66
+  scrollbar-width: none;  /* Firefox */
67
+}
68
+.overflowable::-webkit-scrollbar {
69
+  display: none;
70
+}
71
+blockquote {
72
+  font-size: 1em;
73
+  font-style: italic;
74
+  border: none;
75
+  margin: 0;
76
+}
77
+.scrollbuffer {
78
+  height: 20px;
79
+}
80
+.overflowable:before {
81
+  content:'';
82
+  width:100%;
83
+  height:20px;    
84
+  position:absolute;
85
+  left:0;
86
+  bottom:0;
87
+  right:0;
88
+  background:linear-gradient(transparent 0px, 
89
+    rgba(255, 255, 255, 0.9));
90
+}
54 91
 "
55 92
 
56 93
 attribhtml <- '
@@ -65,3 +102,57 @@ confidentiality-of-info-supplied-to-snz/safeguarding-confidentiality.aspx"
65 102
 title="A method of preserving confidentiality and anonymity">
66 103
 random rounding</a>
67 104
 '
105
+
106
+infotext <- div(class="overflowable",
107
+  h3("How did Kiwis commute in 2018?"),
108
+  p("This tool maps the 2018 census",
109
+  a(href=
110
+    "https://datafinder.stats.govt.nz/data/category/census/2018/commuter-view/", 
111
+    "commuter data"), 
112
+  "to help visualise transport ",
113
+    "connections. It is ", a(href="http://petras.space", "Petra Lamborn's"),
114
+    " entry for the ", em("There and Back Again"),
115
+    a(href=
116
+"https://www.stats.govt.nz/2018-census/there-and-back-
117
+again-data-visualisation-competition", "data visualisation competition",
118
+    .noWS = "after"), ". The source data counts employed persons 15 years or ",
119
+    "older who gave an employment location in the 2018 census."),
120
+  h4("Options"),
121
+  p("The top right panel (toggleable via the blue switch) allows ",
122
+    "you to choose between visualising the people who commute from ",
123
+    "and to each area, and between showing numbers of people or ",
124
+    "their primary mode of transportation."),
125
+  p("Select an area by clicking on it; deselect by clicking it again ",
126
+    "or clicking in the water. When an area is selected the map is ",
127
+    "coloured according to the people who commute to or from that area ",
128
+    "(including the people who commute within the area). When no area is ",
129
+    "selected, colouring is according to commutes to or from all ",
130
+    "localities."),
131
+  h4("FAQ"),
132
+  shiny::tags$blockquote("Why are so many areas purple (for 'works at ",
133
+                         "home')?"),
134
+  p("Working from home includes working from your kitchen table, ",
135
+    "but also farming. Anyone who is employed but does not commute ",
136
+    "is included in this category."),
137
+  shiny::tags$blockquote("Why is every number divisible by three?"),
138
+  p("To ensure anonymity and the confidentiality of your census data, ",
139
+    "Statistics New Zealand employs a technique called ",
140
+    em(a(href=paste0(
141
+      "http://archive.stats.govt.nz/about_us/legisln-policies-protocols/",
142
+      "confidentiality-of-info-supplied-to-snz/safeguarding-confidentiality.aspx"),
143
+         "random rounding", .noWS = "after"), .noWS = "after"), ". ",
144
+    "This method rounds all values to a multiple of three, but one-third of ",
145
+    "the time rounds to the second nearest multiple, rather than the closest. ",
146
+    "Additionally, rounded values less than six are censored."),
147
+    p("Note that this also means totals do not always add up."),
148
+  shiny::tags$blockquote("In some views there are areas that are greyed ",
149
+                         "out when looking at transport type, but not ",
150
+                         "when looking at numbers of people. How does ",
151
+                         "that work?"),
152
+  p("As mentioned above some low values are censored to avoid providing ",
153
+    "potentially identifyable information. However it is possible for the ",
154
+    "total number of people to be large enough to escape censoring while ",
155
+    "all transport", em("type"), "numbers are too small and so no most ",
156
+    "common type can be determined."),
157
+  div(class="scrollbuffer")
158
+)