-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathapp.R
187 lines (171 loc) · 7.34 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
library(shiny)
library(rmarkdown)
library(shinyWidgets)
library(dplyr)
library(shinyalert)
# .shiny-progress.progress-text {
# position: relative;
# top: 50%;
# left: 50%;
# transform: translate(-50%, -50%);
# }
# remaking this so that we can style it (more easily) w css later on
fileInputOnlyButton <- function(..., label = "") {
temp <- fileInput(...,
label = label)
# Cuts away the label
temp$children[[1]] <- NULL
# Cut away the input field (after label is cut, this is position 1 now)
temp$children[[1]]$children[[2]] <- NULL
# Remove input group classes (makes button flat on one side)
temp$children[[1]]$attribs$class <- NULL
temp$children[[1]]$children[[1]]$attribs$class <- NULL
temp
}
# not using fluidpage, since this is more neat
ui <- tabsetPanel(
id = "panels",
type = "hidden",
selected = "main_page",
tabPanelBody(
value = "main_page",
includeCSS(path = "styles.css"),
tags$div(
class = "main_page_content",
tags$h1(
tags$strong("ODK2Doc",
style = "font-size: 100%;
padding-bottom: 0%;"
)
),
tags$div(
class = "main_text",
tags$h4(
HTML(
'<br><br>Welcome to <b>ODK2Doc</b>! This is an app to convert ODK/Kobo survey forms to printable,
and easily editable, .docx documents. <br><br> To begin, upload an xls form using
the upload button (<i class="fa fa-upload" style = "color: #8e8d8d;"></i>) below.
For best results, make sure your form uses the <b><span class="half_background">
<a href = "https://xlsform.org/en/#basic-format/", target="_blank">
default</b></span></a> sheet names and a form title that has been added via the
<b><span class="half_background"> <a href = "https://xlsform.org/en/#settings-worksheet",
target="_blank"> settings</b></span></a> sheet. An example form, with the names required for using this app, can be found <b><span class="half_background"> <a href = "https://docs.google.com/spreadsheets/d/1tUPkbjIv0H2Aoj78kCf0eMAQO-uALoMIEJq4aL1C00I/edit#gid=0",
target="_blank">here</b></span></a>. <br><br> To finish, click on the download button (<i class="fa fa-download" style = "color: #8e8d8d;"></i>),
and wait for few seconds - your converted form will download as soon as it has been compiled!'
)
),
style = "font-size: 90%;
width: 60%;
text-align:justify;
line-height: 1.5;"
),
tags$div(
class = "select_something",
fileInputOnlyButton(
inputId = "file1",
label = "Test",
buttonLabel = list(icon("upload",
style = "color: #8e8d8d",
title = "Upload"),
".xlsx"),
accept = c(".xlsx",
".xls"),
),
),
downloadButton(
outputId = "downloadreport",
icon = icon("download",
style = "color: #8e8d8d"),
class = "select_something",
style = HTML("text-decoration: none;"),
title = "Download",
label = ".docx",
),
tags$div(
# uncomment this chunk to run OG version
checkboxInput(inputId = "checkbox",
label = "Add skip logic?",
value = FALSE,
width = "100%"),
# checkboxGroupInput(inputId = "box",
# label = "",
# choices = c("Type-I" = TRUE,
# "Type-II" = TRUE),
# inline = T),
# tags$div(id = "drop",
# selectInput("state",
# "",
# list("Compressed Format",
# "Compressed Format + Skip",
# "Full length format",
# "Full length format + Skip"))),
),
tags$div(
tags$h3(
# HTML(
# '<b> Note:</b> Currently, the app is in its final testing phase! (This is <b>v2</b>).'
# ),
# style = "font-size: 10px;
# width: 460px;
# text-align: justify;
# padding-top: 40px;"
),
tags$div(
tags$h2(
HTML(
'<i class="fa fa-twitter" style = "color: #8e8d8d;"></i>
<a href = "https://twitter.com/zaeendesouza/", target="_blank">@zaeendesouza</span></a>
<i class="fa fa-twitter" style = "color: #8e8d8d;"></i>
<a href = "https://twitter.com/Kabira_Namit", target="_blank">@Kabira_Namit</span></a>
<i class="fa fa-github" style = "color: #8e8d8d;"></i></i>
<a href = "https://github.com/zaeendesouza/ODK2Doc", target="_blank">ODK2Doc</span></a>'
),
style = "font-size: 10px;
width: 300px;
text-align: center;
padding-top: 40px;"
)
)
),
),
)
)
server <- function(input, output) {
# observeEvent(input$file1, {
#
# shinyalert("We are currently under maintenance. It will work, but there may be errors in your form.", type = "error")
# })
output$downloadreport <-
downloadHandler(
filename = "my-odk-form.docx",
content = function(file) {
withProgress(message = "Please wait, while we convert your form.", {
if (input$checkbox == TRUE) {
src <- normalizePath("report1_compact_skip.Rmd")
owd <- setwd(tempdir())
on.exit(setwd(owd))
file.copy(from = src,
to = "report1_compact_skip.Rmd",
overwrite = T)
out <- render(input = "report1_compact_skip.Rmd",
output_format = word_document(),
params = list(file = input$file1$datapath))
file.rename(out, file)
}else{
src <- normalizePath("report2_compact.Rmd")
owd <- setwd(tempdir())
on.exit(setwd(owd))
file.copy(from = src,
to = "report2_compact.Rmd",
overwrite = T)
out <- render(input = "report2_compact.Rmd",
output_format = word_document(),
params = list(file = input$file1$datapath))
file.rename(out, file)
}
}
)
}
)
}
shiny::shinyApp(ui, server)