Browse Source

change shapefile; add keyboard shortcuts

Petra Lamborn 3 years ago
parent
commit
cb91b97a5f
3 changed files with 53 additions and 8 deletions
  1. 1
    0
      .gitignore
  2. 16
    7
      viz/app.R
  3. 36
    1
      viz/extras.R

+ 1
- 0
.gitignore View File

6
 shapefiles/
6
 shapefiles/
7
 *.RData
7
 *.RData
8
 viz/sa20025WGSfilcth/
8
 viz/sa20025WGSfilcth/
9
+viz/sa20025WGSfil/

+ 16
- 7
viz/app.R View File

11
 
11
 
12
 # work_travel <- read_csv("../travel-work.csv")
12
 # work_travel <- read_csv("../travel-work.csv")
13
 load(file="datasets.RData")
13
 load(file="datasets.RData")
14
-shpf <- readOGR(dsn="sa20025WGSfilcth")
14
+shpf <- readOGR(dsn="sa20025WGSfil")
15
 sa.in.dest <- shpf@data$SA22018_V1 %in% work_to$work_code
15
 sa.in.dest <- shpf@data$SA22018_V1 %in% work_to$work_code
16
 sa.in.home <- shpf@data$SA22018_V1 %in% work_from$res_code
16
 sa.in.home <- shpf@data$SA22018_V1 %in% work_from$res_code
17
 transport.t <- c("Private car", "Passenger in car",
17
 transport.t <- c("Private car", "Passenger in car",
47
 ui <- fluidPage(
47
 ui <- fluidPage(
48
   useShinyjs(),
48
   useShinyjs(),
49
   leafletjs,
49
   leafletjs,
50
+  keyboardjs,
50
   tags$style(type = "text/css", extracss),
51
   tags$style(type = "text/css", extracss),
52
+  
51
   leafletOutput("map"),
53
   leafletOutput("map"),
52
   absolutePanel(top = 10, right = 10, id="mapcontrol",
54
   absolutePanel(top = 10, right = 10, id="mapcontrol",
53
                 div(
55
                 div(
54
                 radioButtons("radioeduemp", 
56
                 radioButtons("radioeduemp", 
55
                              label = "Commuters (age 15+) travelling to",
57
                              label = "Commuters (age 15+) travelling to",
56
-                             choices = c("Employment", "Education"),
58
+                             choiceNames = list(
59
+                               HTML("<span>E<u>m</u>ployment</span>"),
60
+                               HTML("<span>E<u>d</u>ucation</span>")
61
+                             ),
62
+                             choiceValues = list(
63
+                               "Employment", "Education"
64
+                             ),
57
                              inline = TRUE),
65
                              inline = TRUE),
58
                 radioButtons("radioinout", label="Show commuters who",
66
                 radioButtons("radioinout", label="Show commuters who",
59
                              choiceNames = list(
67
                              choiceNames = list(
60
-                               HTML("<p>Commute <b>from</b> selected area</p>"),
61
-                               HTML("<p>Commute <b>to</b> selected area</p>")),
68
+                               HTML("<span>Commute <u>f</u>rom selected area</span>"),
69
+                               HTML("<span>Commute <u>t</u>o selected area</span>")),
62
                              choiceValues = list(
70
                              choiceValues = list(
63
                                "res",
71
                                "res",
64
                                "work"
72
                                "work"
67
                 radioButtons("radiocolour",
75
                 radioButtons("radiocolour",
68
                              label = "Colour by",
76
                              label = "Colour by",
69
                              choiceNames = list(
77
                              choiceNames = list(
70
-                               HTML("<p>Most common commute method</p>"),
71
-                               HTML("<p>Number of commuters</p>")
78
+                               HTML("<span>M<u>o</u>st common commute method</span>"),
79
+                               HTML("<span>N<u>u</u>mber of commuters</span>")
72
                              ),
80
                              ),
73
                              choiceValues = list(
81
                              choiceValues = list(
74
                                "type",
82
                                "type",
110
     ifelse(lastout == lastover, 0, lastover)
118
     ifelse(lastout == lastover, 0, lastover)
111
   })
119
   })
112
   output$map <- renderLeaflet({
120
   output$map <- renderLeaflet({
113
-    leaf <- leaflet(shpf, options = leafletOptions(minZoom = 3, maxZoom = 13)) %>% 
121
+    leaf <- leaflet(shpf, options = leafletOptions(minZoom = 3, maxZoom = 13,
122
+                                                   crs = NULL)) %>% 
114
       addPolygons(color="#000", opacity = 1, weight=1,
123
       addPolygons(color="#000", opacity = 1, weight=1,
115
                                 fillColor = startcols.res, 
124
                                 fillColor = startcols.res, 
116
                   layerId = ~SA22018_V1,
125
                   layerId = ~SA22018_V1,

+ 36
- 1
viz/extras.R View File

158
     "coloured according to the people who commute to or from that area ",
158
     "coloured according to the people who commute to or from that area ",
159
     "(including the people who commute within the area). When no area is ",
159
     "(including the people who commute within the area). When no area is ",
160
     "selected, colouring is according to commutes to or from all ",
160
     "selected, colouring is according to commutes to or from all ",
161
-    "localities. Hover over areas for a summary."),
161
+    "localities. Hover over areas for a summary (on a tablet, hold press)."),
162
   h4("FAQ"),
162
   h4("FAQ"),
163
   shiny::tags$blockquote("Why are so many areas marked as 'works at ",
163
   shiny::tags$blockquote("Why are so many areas marked as 'works at ",
164
                          "home'?"),
164
                          "home'?"),
187
     "common type can be determined."),
187
     "common type can be determined."),
188
   div(class="scrollbuffer")
188
   div(class="scrollbuffer")
189
 )
189
 )
190
+
191
+keyboardjs <- tags$head(tags$script(HTML("
192
+$(function(){ 
193
+  $(document).keyup(function(e) {
194
+    switch(e.key) {
195
+      case 'm':
196
+        document.getElementsByName('radioeduemp')[0].checked = true;
197
+        Shiny.onInputChange('radioeduemp', 'Employment')
198
+        break;
199
+      case 'd':
200
+        document.getElementsByName('radioeduemp')[1].checked = true;
201
+        Shiny.onInputChange('radioeduemp', 'Education')
202
+        break;
203
+      case 'f':
204
+        document.getElementsByName('radioinout')[0].checked = true;
205
+        Shiny.onInputChange('radioinout', 'res')
206
+        break;
207
+      case 't':
208
+        document.getElementsByName('radioinout')[1].checked = true;
209
+        Shiny.onInputChange('radioinout', 'work')
210
+        break;
211
+      case 'o':
212
+        document.getElementsByName('radiocolour')[0].checked = true;
213
+        Shiny.onInputChange('radiocolour', 'type')
214
+        break;
215
+      case 'u':
216
+        document.getElementsByName('radiocolour')[1].checked = true;
217
+        Shiny.onInputChange('radiocolour', 'number')
218
+        break;
219
+      default:
220
+        break;
221
+    }
222
+  });
223
+})
224
+")))