-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathui.R
382 lines (310 loc) · 15.3 KB
/
ui.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
require(shiny)
require(shinydashboard)
require(tidyverse)
require(stringr)
require(scales)
require(grid)
require(ggrepel)
require(readxl)
#require(DT)
# common features --------------------------------------------------------------
CAList <- list("Scotland", "Aberdeen City", "Aberdeenshire", "Angus",
"Argyll and Bute", "City of Edinburgh",
"Clackmannanshire", "Dumfries and Galloway",
"Dundee City", "East Ayrshire", "East Dunbartonshire",
"East Lothian", "East Renfrewshire", "Falkirk", "Fife",
"Glasgow City", "Highland", "Inverclyde", "Midlothian",
"Moray", "Na h-Eileanan Siar", "North Ayrshire",
"North Lanarkshire", "Orkney Islands", "Perth and Kinross",
"Renfrewshire", "Scottish Borders", "Shetland Islands",
"South Ayrshire", "South Lanarkshire", "Stirling",
"West Dunbartonshire", "West Lothian")
popStartYr <- 1998
popEndYr <- 2018
# ------------------------------------------------------------------------------
ui <- dashboardPage(title="Population Estimates of Scotland - National Records of Scotland",
dashboardHeader(
title = tags$a(href='http://www.nrscotland.gov.uk',
tags$img(height="45", alt="NRS", src="logo.png"),
tags$script(
HTML(paste0('$(document).ready(function() {
$("header").find("nav").append(\'<span class="myClass">',
'Mid-Year Population Estimates for Scotland, 2018',
'</span>\');
})' ))),
tags$head(
tags$style(
HTML('.myClass {
font-size: 18px;
line-height: 50px;
text-align: left;
padding: 0 15px;
overflow: hidden;
color: white;
font-family: "Roboto", sans-serif !important; font-weight:400;
}')),
HTML('<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Roboto: 100,200,300,400,500,900">'))
)
),
dashboardSidebar(
sidebarMenu(
menuItem("Introduction", tabName = "tab_Intro", icon = icon("th")),
menuItem("Population", tabName = "tab_Pop", icon = icon("line-chart")), #here add name of the menu items
menuItem("Components of change", tabName = "tab_CompCh", icon = icon("circle")),
menuItem("Population Structure", tabName = "tab_Struct", icon = icon("area-chart")),
menuItem("Population by age", tabName = "tab_Age", icon = icon("bar-chart")),
menuItem("% change by council", tabName = "tab_ChCA", icon = icon("bar-chart")),
menuItem("% change timeseries", tabName = "tab_ChCALine", icon = icon("line-chart")),
#menuSubItem("Sub-item 1", tabName = "tab1"), # as an argument within menuItem
#menuSubItem("Sub-item 2", tabName = "subitem2"),
#menuSubItem("Sub-item 3", tabName = "subitem3")
menuItem(HTML("More information"), tabName = "tab_MoreInfo", icon = icon("info")))
),
# ------------------------------------------------------------------------------
dashboardBody(
HTML("<script src='https://cc.cdn.civiccomputing.com/8/cookieControl-8.x.min.js'></script>"),
HTML("<script async src='https://www.googletagmanager.com/gtag/js?id=UA-91956629-1'></script>"),
tags$script(src = "cookie_control_config.js"),
#adding css file
tags$head(
includeCSS("style.css")
),
tabItems(
# - Tab 0 ----------------------------------------------------------------------
tabItem(tabName = "tab_Intro",
fluidPage(
titlePanel("Introduction"),
br(),
h4("This interactive visualisation shows the", (strong("mid-year
population estimates for Scotland")), "from 1998 to 2018. The
estimates and change over time can also be broken down by age and
council area."),
h4("The latest estimate of Scotland's population (on 30 June 2018) is",
strong("5,438,100"),"the highest ever and an increase of 13,300
people (0.2%) over the last year."),
h4("Since 1998, Scotland's population has increased by 7%."),
br()
)
),
# - Tab 1 - Population time series -----------------------------------------------------------
tabItem(tabName = "tab_Pop",
fluidPage(
titlePanel("Population"),
fluidRow(
# - Side menu ----------------------------------------------------------
column(4,
wellPanel(
helpText("Please select options for chart") ,
br(),
selectInput("Area_Pop", label="Area:", selected="Scotland",
choices=CAList),
br(),
sliderInput("Years_Pop", "Years:",
min = popStartYr, max = popEndYr,
value = c(popStartYr, popEndYr),sep="")
)
),
# - Plot ---------------------------------------------------------------
column(8,
wellPanel(
plotOutput("plot_Pop"))
))
)),
# - Tab 2 - Components of change --------------------------------------------------------
tabItem(tabName = "tab_CompCh",
fluidPage(
titlePanel("Components of Change on year"),
fluidRow(
# - Side menu ----------------------------------------------------------
column(4,
wellPanel(
helpText("Please select options for chart") ,
br(),
selectInput("Area_CompCh", label="Area:", selected="Scotland",
choices=CAList)
)
),
# - Plot ---------------------------------------------------------------
column(8,
wellPanel(
plotOutput("plot_CompCh"))
))
)),
# - Tab 3 - Population structure -------------------------------------------------
tabItem(tabName = "tab_Struct",
fluidPage(
titlePanel("Population Structure"),
fluidRow(
# - Side menu ----------------------------------------------------------
column(4,
wellPanel(
helpText("Please select options for chart") ,
br(),
selectInput("Area_Struct", label="Area:", selected="Scotland",
choices=CAList),
br(),
sliderInput("Years_Struct", "Years:",
min = popStartYr, max = popEndYr,
value = c(popStartYr, popEndYr),sep="")
)
),
# - Plot ---------------------------------------------------------------
column(8,
wellPanel(
plotOutput("plot_Struct"))
))
)),
# - Tab 4 - Population by age -------------------------------------------------
tabItem(tabName = "tab_Age",
fluidPage(
titlePanel("Population by age"),
fluidRow(
# - Side menu ----------------------------------------------------------
column(4,
wellPanel(
helpText("Please select options for chart") ,
br(),
selectInput("Area_Age", label="Area:", selected="Scotland",
choices=CAList),
br(),
sliderInput("Years_Age", "Years:",
min = popStartYr, max = popEndYr,
value = c(popStartYr, popEndYr),sep="")
)
),
# - Plot ---------------------------------------------------------------
#dynamic version (hides difference graph if years identical)
column(8,
wellPanel(
plotOutput("plot_Age")),
#only show difference if there is more than one year selected
conditionalPanel(
condition="output.Years_Age_Different",
wellPanel(
plotOutput("plot_ChAge"))
)
))
)),
# - Tab 5 - % change by CA -------------------------------------------------
tabItem(tabName = "tab_ChCA",
fluidPage(
titlePanel("Percentage change by council"),
fluidRow(
# - Side menu ----------------------------------------------------------
column(4,
wellPanel(
helpText("Please select options for chart") ,
br(),
selectInput("Area_ChCA", label="Area:", selected="Scotland",
choices=CAList),
br(),
sliderInput("Years_ChCA", "Years:",
min = popStartYr, max = popEndYr,
value = c(popStartYr, popEndYr),sep="")
)
),
# - Plot ---------------------------------------------------------------
column(8,
wellPanel(
plotOutput("plot_ChCA",height="500px"))
))
)),
# - Tab 5 - % annual change by CA -------------------------------------------------
tabItem(tabName = "tab_ChCALine",
fluidPage(
titlePanel("Percentage change by council - timeseries"),
fluidRow(
# - Side menu ----------------------------------------------------------
column(4,
wellPanel(
helpText("Please select options for chart") ,
br(),
selectInput("Area_ChCALine", label="Area:", selected="Scotland",
choices=CAList),
br(),
sliderInput("Years_ChCALine", "Years:",
min = popStartYr, max = popEndYr,
value = c(popStartYr, popEndYr),sep="")
)
),
# - Plot ---------------------------------------------------------------
column(8,
wellPanel(
plotOutput("plot_ChCALine",height="500px"))
))
)),
# - More information----------------------------------------------------------------
tabItem(tabName = "tab_MoreInfo",
fluidPage(
titlePanel("More information"),
fluidRow(
column(12,
br(),
p("Mid-year population estimates are based on the Census and are updated
annually to account for population change in the period
from 1 July to 30 June. Therefore, the period covered by the
latest mid-2018 statistics (1 July 2017 to 30 June 2018) is
two years after the referendum on European Union membership (which took place on 23
June 2016)."),
p("The two main contributors to population change are natural change (births minus
deaths) and net migration (the difference between long-term moves into and out
of Scotland or local areas)."),
p("The estimated population of an area includes all those usually resident there,
whatever their nationality. Population figures relate to 30 June of the year shown
and ages relate to age at last birthday. Long-term international
migrants are included, but short-term migrants are
excluded. A long-term migrant is defined by the United Nations (UN)
as someone who changes country of residence for 12 months or more."),
p("Population estimates are used for a variety of purposes including resource
allocation and planning of services such as education and health. They are
also used for calculating rates and performance measures, informing local
and national policy, weighting surveys and in modelling the economy."),
p("Mid-year population estimates for 2019 will be published in spring 2020."),
p("More information about the estimates, their uses and their
limitations can be found on the",
a("Mid-Year Population Estimates",
href="https://www.nrscotland.gov.uk/statistics-and-data/statistics/statistics-by-theme/population/population-estimates/mid-year-population-estimates",
target="_blank"),
"page on the NRS website. More detailed information is available in the Mid-year Population Estimates for Scotland ",
HTML(paste0(a("Methodology Guide",
href="https://www.nrscotland.gov.uk/statistics-and-data/statistics/statistics-by-theme/population/population-estimates/mid-year-population-estimates/mid-2018",
target="_blank"),
"."))),
br(),
fluidRow(
column(4,
h6(strong("More information")),
h6("Data: ", a("Mid-Year Population Estimates, Mid-2018 (csv)",
href="https://www.nrscotland.gov.uk/files//statistics/nrs-visual/mid-18-pop-est/mid-year-pop-est-18-data-vis.xlsx",
target="_blank")),
h6("Publication: ", a("Mid-Year Population Estimates, Mid-2018",
href="https://www.nrscotland.gov.uk/statistics-and-data/statistics/statistics-by-theme/population/population-estimates/mid-year-population-estimates/mid-2018",
target="_blank"))),
column(4,
br(),
h6("Follow us on Twitter - ",
a("@NatRecordsScot",
href="https://twitter.com/NatRecordsScot",
target="_blank")),
h6("See more ",
a("Infographics & Visualisations",
href="http://www.nrscotland.gov.uk/statistics-and-data/statistics/stats-at-a-glance/infographics-and-visualisations",
target="_blank"))),
column(4,
br(),
h6(a("National Records of Scotland", href="http://www.nrscotland.gov.uk", target="_blank")),
h6("© Crown Copyright 2019 - ",
a("Copyright conditions",
href="http://www.nationalarchives.gov.uk/doc/open-government-licence/version/3/",
target="_blank")))
),
br(),
p("Any feedback about this visualisation?",
a("Get in touch!", href="mailto:statisticscustomerservices@nrscotland.gov.uk?subject=Mid-year%20Population%20Estimates%20of%20Scotland%20visualisation"))
) #end column
) #end fluidRow
) #end fluidPage
) #tab4 end
) #tabItems
) #dashboardBody
) #dashboardPage