-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.R
213 lines (177 loc) · 6.33 KB
/
app.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
# Needed libraries to run the app
library(shiny)
library(bslib)
library(tidyverse)
library(magrittr)
library(WordR)
library(flextable)
library(officer)
library(openxlsx)
library(lubridate)
library(janitor)
library(googledrive)
library(emo)
library(shinyWidgets)
library(readxl)
library(readr)
library(devtools)
# Authenticate googledrive
# Informations to authenticate are stored in an .Rprofile
googledrive::drive_auth()
# User interface
ui <- fluidPage(
# Calling of shinyjs package for functionality in `server`
shinyjs::useShinyjs(),
theme = bs_theme(bg = "#f6f6f6", fg = "#1D4044",
base_font = font_google("Lato"), "progress-bar-bg" = "orange"),
# Change web window title + adding the CSS styling
tags$head(
HTML("<title> Create KBA summary </title>"),
includeCSS("www/styles.css")
),
# Add the titlepanel which is modified in the .css file
HTML("<h1><a href='https://kbacanadawiki.org/'>
<img src='./Canada_KBA_transparent_white.png'style='position: relative;
float: left;left: 6%; padding-bottom: 10px;
width: 5%; height: 5%;' alt='KBA_logo'/></a>Creation of KBA summaries</h1>"),
# Spaces before the panels
br(),
fluidRow(
column(width = 3, offset = 1,
wellPanel(class = "well", h2("ReadMe"),
hr(),
h5("This Shiny application is intended to convert KBA
Canada proposal forms into KBA summaries for expert review."),
h3("How to proceed:"),
hr(),
h4("1- Select review stage."),
h4("2- Select language."),
h4("3- Upload the desired proposals to convert."),
h4("4- Click convert button to summarize."),
h4("(Process might take a couple seconds to start)"),
h4("5- Check result table to see which
proposals were correctly processed."),
h4("6- Download!"),
hr(),
h5("Developed by Benjamin Mercier and
Chloé Debyser for the KBA Canada Secretariat"),
h6("Source code",
tags$a(href = "https://github.com/BenMerSci/KBA_shinyforms",
icon("github", "fa-2x"))),
tags$style(".fa-github {color:#13294B}"),
)
),
column(width = 4,
wellPanel(class = "well", h2("Input"),
hr(),
radioButtons(
"stageRev",
h3("Select review stage"),
choices = list("Technical Review" = "technicalRev",
"General Review" = "generalRev",
"Steering Committee" = "steeringRev"),
selected = "technicalRev", inline = TRUE),
tags$div(
h3("Select language"),
materialSwitch(
inputId = "language",
label = h4("English",
style = "margin-top: -15%; display: inline"),
value = F,
inline = T,
right = F,
width="50%"),
tags$span(h4("Français",
style = "margin-left: -28%; display: inline"))
),
fileInput("file", label = h3("Upload your proposal(s)"),
placeholder = "or drop files here",
multiple = TRUE,
accept = c(".xlsm"),
width = "120%"),
hr(),
br(),
tags$div(uiOutput("runButton"), align = "center"),
)
),
column(width = 4,
wellPanel(class = "well_scroll", h2("Output"),
hr(),
br(),
tags$div(downloadButton("downloadData", "Download"), align = "center"),
br(),
tags$div(tableOutput("resTable"), align = "center"),
)
),
),
fluidRow(
column(12,
tags$div(class = "footer",
HTML("Photograph © Tony Webster, <a rel='noreferrer noopener'
href='https://www.flickr.com/photos/diversey/22492133101/in/photolist-
Agy4yi-4hP5D-2jiQL9m-2iqMZ89-Q4p8C3-gAnYRA-24Z34E4-PuPSu3-2kjavbz-
2kbsmz1-2iqP7Fu-nmFr4C-zbb2AM-qeoBfK-nYdH9B-RASxd7-Qd1Sgq-2f2oPXZ-
qzAw71-8MVKVd-T7niUj-etMN7D-DkStuM-55gdqb-2j8xytN-qcnKee-gAo3X9-ur89y7-
gAkQjM-5iBJJR-diC8TQ-aS2LbM-pq2Y4k-5iG1qG-5iBJiZ-g88dhq-2j8xywt-5iBJh8-
u9XuRf-PE5GWE-2kJ5z3N-5iG1SY-JTZ92V-5iBJBn-3gaoc2-Cudqzt-2koJsqF-
2jd9VDJ-6y7wxz-dk4Aui/' target='_blank'>Lake of Shining Waters -
Prince Edward Island National Park</a>
(cropped) <a rel='noreferrer noopener'
href='https://creativecommons.org/licenses/by-sa/2.0/'
target='_blank'>CC BY-SA 2.0</a>")
)
)
)
)
server <- function(input, output) {
source("R/KBA_summary.R")
shinyjs::hide("downloadData")
file_df <- reactive({
req(input$file)
df <- input$file
})
output$runButton <- renderUI({
if(is.null(file_df())) return()
actionButton("runScript", "Convert to summary")
})
getReviewStage <- reactive({
if(input$stageRev == "technicalRev") return("technical")
if(input$stageRev == "generalRev") return("general")
if(input$stageRev == "steeringRev") return("steering")
})
getLanguage <- reactive({
if(!input$language) return("english")
if(input$language) return("french")
})
r <- reactiveValues(convertRes = NULL)
observeEvent(input$runScript, {
shinyjs::disable("runScript")
shinyjs::hide("downloadData")
shinyjs::hide("resTable")
r$convertRes <- form_conversion(KBAforms = file_df()$datapath, reviewStage = getReviewStage(), language = getLanguage(), app = T)
output$resTable <- renderTable(r$convertRes[[2]])
shinyjs::show("resTable")
output$downloadData <- downloadHandler(
filename = function() if(length(file_df()$name) == 1){
r$convertRes[[1]]
}else{"Summaries.zip"},
content = function(file) if(length(file_df()$name) == 1){
file.rename(from = r$convertRes[[1]], to = file)
}else{
# create a temp folder for shp files
temp_fold <- tempdir()
zip_file <- paste0(temp_fold,"/Summaries.zip")
zip(zipfile = zip_file, files = r$convertRes[[1]])
# copy the zip file to the file argument
file.copy(zip_file, file, overwrite = TRUE)
# remove all the files created
file.remove(zip_file)
}
)
rm(delineationRationale, includeGlobalTriggers, includeNationalTriggers,
juris, lat, lon, nationalName, proposalLead, scope, siteDescription,
noFeedback, envir = sys.frame())
shinyjs::show("downloadData")
}, ignoreNULL = TRUE, ignoreInit = TRUE)
}
shinyApp(ui, server)