-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstep_5_run_document_for_dashboard.Rmd
More file actions
229 lines (189 loc) · 6.87 KB
/
step_5_run_document_for_dashboard.Rmd
File metadata and controls
229 lines (189 loc) · 6.87 KB
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
---
title: "B.C. Major Project Inventory"
date: "`r paste0('updated: ',as.Date(file.info(here::here('processed_data','mpi_shortraw.rds'))$mtime-lubridate::hours(7)))`"
output:
flexdashboard::flex_dashboard:
orientation: rows
social: menu
source_code: "https://github.com/bcgov/MPI-R"
css: style.css
runtime: shiny
resource_files:
- processed_data/by_region_tables.rds
- processed_data/by_region_plots.rds
- processed_data/by_region_commentary.rds
- processed_data/all_regions_tables.rds
- processed_data/all_regions_plots.rds
- processed_data/mpi_shortraw.rds
- .Rprofile
- processed_data/long_aggregated.rds
- processed_data/long_aggregated.rds
- .secrets/d67d4efb39eee449dc62932502fd8a0f_rich.p.martin@gmail.com
---
```{r global, include=FALSE}
# Copyright 2022 Province of British Columbia
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and limitations under the License.
#libraries----------
library(tidyverse)
library(shinyWidgets)
library(googlesheets4)
#load objects----------
short <- readRDS(here::here("processed_data", "mpi_shortraw.rds"))
by_region_tables <- readRDS(here::here("processed_data","by_region_tables.rds"))
all_regions_tables <- readRDS(here::here("processed_data","all_regions_tables.rds"))
by_region_plots <- readRDS(here::here("processed_data","by_region_plots.rds"))
all_regions_plots <- readRDS(here::here("processed_data","all_regions_plots.rds"))
long_aggregated <- readRDS(here::here("processed_data","long_aggregated.rds"))
#functions------------
#Extractor function (retrieve cell) for all_regions_* dataframes----------
extract_all_regions_cell <- function(df, name){
df <- df%>%
filter(thing_name==name)%>%
select(value)%>%
pull()
df<- df[[1]]
if(is.data.frame(df)){
colnames(df) <- colnames(df)%>%
str_replace_all("_"," ")%>%
str_to_title()
}
return(df)
}
#Extractor function (retrieve cell) for by_region_* dataframes-------------
datatable_cell <- function(df, type, reg){
df <- df%>%
filter(region==reg)%>%
select(all_of(type))%>%
pull()
df<- df[[1]]
if(is.data.frame(df)){
colnames(df) <- colnames(df)%>%
str_replace_all("_"," ")%>%
str_to_title()
}
return(df)
}
```
# Regional Map
## Inputs {.sidebar}
<br>
- This dashboard contains two Maps and Provincial and Regional analyses of Major Projects.
- You can navigate to these sections by clicking on the header bar.
- The data used in the Provincial and Regional analyses can be downloaded from the table tab.
- All data retrieved from [British Columbia's Major Project Inventory](https://www2.gov.bc.ca/gov/content/employment-business/economic-development/industry/bc-major-projects-inventory/recent-reports).
<br>
### User survey:
```{r}
textInput(
"who",
"Tell us a bit about yourself: e.g. who do you work for?")
textInput(
"what",
"What do you use the MPI for?")
textInput(
"features",
"What additional features would you like to see?")
actionButton("submit", "Submit")
textB <- reactive({
as.data.frame(c(input$who, input$what, input$features))
})
observeEvent(input$submit, {
Selfie <- gs4_get('https://docs.google.com/spreadsheets/d/1ZK7PmApXRzVgmeSY6i3Hf7rWLUsvJjVbgyJ4LAS0ECc/edit?usp=sharing')
sheet_append(Selfie, data = textB())
showNotification("Thanks for your feedback.")
})
```
## Column
### MPI by region in `r max(all_regions_tables[[2]][[2]]$quarter)`:
```{r}
wrapR::bc_reg_choro(long_aggregated, region, name, value, "comma")
```
# By type and stage
## Column
### MPI by region type and stage in `r max(all_regions_tables[[2]][[2]]$quarter)`:

# Provincial Analysis
## Inputs {.sidebar}
<br>
```{r}
selectInput("name", label = "Choose a slice of data:",
choices = all_regions_tables$thing_name, selected = all_regions_tables$thing_name[1])
```
## Column {.tabset}
### Plot:
```{r}
plotly::renderPlotly({
extract_all_regions_cell(all_regions_plots, input$name)
})%>%
bindCache(input$name)
```
### Table:
```{r}
DT::renderDataTable(server=FALSE,{
extract_all_regions_cell(all_regions_tables, input$name)%>%
DT::datatable(extensions = "Buttons",
options = list(rownames = FALSE,
columnDefs = list(list(className = 'dt-center', targets = "_all")),
paging = TRUE,
scrollX=TRUE,
scrollY=TRUE,
searching = TRUE,
ordering = TRUE,
dom = 'Btip',
buttons = list(
list(extend = 'csv', filename = paste("MPI-BC", input$name, sep = "-")),
list(extend = 'excel', filename = paste("MPI-BC", input$name, sep = "-"))
),
pageLength=10,
lengthMenu=c(3,5)))
})%>%
bindCache(input$name)
```
# Regional Analysis
## Inputs {.sidebar}
<br>
```{r}
selectInput("region", label = "Which Region:",
choices = by_region_tables$region, selected = by_region_tables$region[1])
selectInput("table", label = "Which Data:",
choices = sort(colnames(by_region_tables)[-1]), selected = sort(colnames(by_region_tables)[-1])[1])
```
## Column {.tabset}
### Plot:
```{r}
plotly::renderPlotly({
datatable_cell(by_region_plots, input$table, input$region)
})%>%
bindCache(input$table, input$region)
```
### Table:
```{r}
DT::renderDataTable(server=FALSE,{
datatable_cell(by_region_tables, input$table, input$region)%>%
DT::datatable(extensions = "Buttons",
options = list(rownames = FALSE,
columnDefs = list(list(className = 'dt-center', targets = "_all")),
paging = TRUE,
scrollX=TRUE,
scrollY=TRUE,
searching = TRUE,
ordering = TRUE,
dom = 'Btip',
buttons = list(
list(extend = 'csv', filename = paste("MPI", input$region, input$table, sep = "-")),
list(extend = 'excel', filename = paste("MPI", input$region, input$table, sep = "-"))
),
pageLength=10,
lengthMenu=c(3,5)))
})%>%
bindCache(input$table, input$region)
```