Skip to content

Commit 66995bc

Browse files
author
Jan Červený
authored
Merge pull request #9 from GCRI-DoAB/excel-functionality-implementation
Excel functionality implementation
2 parents 28cf0d2 + 33e90a5 commit 66995bc

8 files changed

Lines changed: 147 additions & 82 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.Rhistory

google-analytics.js

Whitespace-only changes.

mlabDB-connect.R

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
mLab <- list("insert")
2+
mLab$insert <- function(data){}

server.R

Lines changed: 102 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,85 @@
1-
2-
3-
41
# This is the server logic for a Shiny web application.
52
# You can find out more about building applications with Shiny here:
63
#
74
# http://shiny.rstudio.com
85
#
96

7+
options( shiny.maxRequestSize = 12 * 1024 ^ 2 )
8+
options( java.parameters = "-Xmx4g" )
9+
1010
library(shiny)
1111
library(dplyr)
12+
library(dtplyr)
1213
library(tidyr)
1314
library(mongolite)
15+
library(xlsx)
1416

15-
options(shiny.maxRequestSize = 10 * 1024 ^ 2)
16-
17-
#url <- "mongodb://SAServer:DoAB@ds048279.mlab.com:48279/shinyapps"
18-
#collection <- "TidyUpPBRData"
19-
#mLab <- mongo(collection, url = url)
17+
source("mlabDB-connect.R", echo = FALSE)
2018

2119
shinyServer(function(input, output, session) {
2220
observeEvent(input$send, {
23-
# mLab$insert(
24-
# data.frame(
25-
# Sys.Date(),
26-
# "User",
27-
# input$name,
28-
# input$surname,
29-
# input$email,
30-
# input$organization,
31-
# input$department
32-
# )
33-
# )
21+
mLab$insert(
22+
data.frame(
23+
Sys.Date(),
24+
"User",
25+
input$name,
26+
input$surname,
27+
input$email,
28+
input$organization,
29+
input$department
30+
)
31+
)
3432
updateActionButton(session, "send",
3533
label = "Successfully Sent!")
3634
}, ignoreNULL = TRUE)
3735

3836
dataInput <- reactive({
39-
inFile <- input$file1
40-
if (is.null(inFile))
37+
if (is.null(input$datafile))
4138
return(NULL)
42-
if (inFile$type == 'application/x-zip-compressed')
43-
fileunz = unzip(inFile$datapath)
44-
else
45-
fileunz <- inFile$datapath
46-
untidydata <- read.table(
47-
fileunz,
48-
header = input$header,
49-
sep = input$sep,
50-
dec = input$dec
39+
withProgress(message = "Processing uploaded data...", value = 0.4, {
40+
if (input$datafile$type == 'application/x-zip-compressed') {
41+
fileunz = unzip(input$datafile$datapath)
42+
untidydata <- read.table(
43+
fileunz,
44+
header = input$header,
45+
sep = input$sep,
46+
dec = input$dec
47+
)
48+
}
49+
else if (input$datafile$type == 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet') {
50+
fileunz <- input$datafile$datapath
51+
untidydata <- data.table(
52+
read.xlsx2(
53+
fileunz,
54+
sheetName = "Data"
55+
)
56+
)
57+
incProgress(0.4)
58+
as.numeric.factor <- function(x) {as.numeric(levels(x))[x]}
59+
datacolnames <- colnames(untidydata)
60+
untidydata[, (datacolnames) := lapply(.SD, as.numeric.factor), .SDcols = datacolnames]
61+
}
62+
else {
63+
fileunz <- input$datafile$datapath
64+
untidydata <- read.table(
65+
fileunz,
66+
header = input$header,
67+
sep = input$sep,
68+
dec = input$dec
69+
)
70+
}
71+
})
72+
mLab$insert(
73+
data.frame(
74+
Sys.Date(),
75+
"File",
76+
input$datafile$name,
77+
input$datafile$type,
78+
input$datafile$size,
79+
input$datafile$datapath
80+
)
5181
)
52-
# mLab$insert(
53-
# data.frame(
54-
# Sys.Date(),
55-
# "File",
56-
# inFile$name,
57-
# inFile$type,
58-
# inFile$size,
59-
# inFile$datapath
60-
# )
61-
# )
62-
if (inFile$type == 'application/x-zip-compressed')
82+
if (input$datafile$type == 'application/x-zip-compressed')
6383
file.remove(fileunz)
6484
return(untidydata)
6585
})
@@ -71,17 +91,17 @@ shinyServer(function(input, output, session) {
7191
})
7292

7393
output$filename <- renderText({
74-
if (!is.null(input$file1$name))
75-
paste("Uploaded file name is ", input$file1$name)
94+
if (!is.null(input$datafile$name))
95+
paste("Uploaded file name is ", input$datafile$name)
7696
})
7797
output$filesize <- renderText({
78-
if (!is.null(input$file1$size))
98+
if (!is.null(input$datafile$size))
7999
paste("Uploaded file size is ",
80-
round(input$file1$size / 1024),
100+
round(input$datafile$size / 1024),
81101
" kB")
82102
})
83103
output$inputdim <- renderText({
84-
if (!is.null(input$file1$size))
104+
if (!is.null(input$datafile$size))
85105
paste(
86106
"Uploaded table dimensions are ",
87107
dim(dataInput())[1],
@@ -91,7 +111,7 @@ shinyServer(function(input, output, session) {
91111
)
92112
})
93113
output$processeddim <- renderText({
94-
if (!is.null(input$file1$size))
114+
if (!is.null(input$datafile$size))
95115
paste(
96116
"Processed table dimensions are ",
97117
dim(dataProcessed())[1],
@@ -104,25 +124,45 @@ shinyServer(function(input, output, session) {
104124
# This function returns a string which tells the client
105125
# browser what name to use when saving the file.
106126
filename = function() {
107-
filetype <-
108-
switch(input$sep,
109-
";" = "csv",
110-
"," = "csv",
111-
"\t" = "tsv")
112-
paste("TidyData", filetype, sep = ".")
113-
},
114-
127+
if (input$datafile$type == 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet')
128+
paste(input$datafile$name)
129+
else {
130+
filetype <-
131+
switch(input$sep,
132+
";" = "csv",
133+
"," = "csv",
134+
"\t" = "tsv")
135+
paste("TidyData", filetype, sep = ".")
136+
}
137+
}
138+
,
115139
# This function should write data to a file given to it by
116140
# the argument 'file'.
117141
content = function(file) {
118142
# Write to a file specified by the 'file' argument
119-
write.table(
120-
dataProcessed(),
121-
file = file,
122-
sep = input$sep,
123-
dec = input$dec,
124-
row.names = FALSE
125-
)
143+
if (input$datafile$type == 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet') {
144+
withProgress(message = "Writing processed data...", value = 0.4, {
145+
write.xlsx2(
146+
data.frame(dataProcessed()),
147+
input$datafile$datapath,
148+
sheetName = "TidyData",
149+
row.names = FALSE,
150+
append = TRUE,
151+
showNA = TRUE
152+
)
153+
incProgress(0.4)
154+
file.copy(input$datafile$datapath, file)
155+
})
156+
}
157+
else {
158+
write.table(
159+
dataProcessed(),
160+
file = file,
161+
sep = input$sep,
162+
dec = input$dec,
163+
row.names = FALSE
164+
)
165+
}
126166
}
127167
)
128168
})

ui.R

Lines changed: 42 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
2-
3-
41
# This is the user-interface definition of a Shiny web application.
52
# You can find out more about building applications with Shiny here:
63
#
@@ -10,21 +7,22 @@
107
library(shiny)
118

129
shinyUI(fluidPage(
13-
#tags$head(includeScript("google-analytics.js")),
14-
15-
titlePanel("Tidy Up PBR Data"),
10+
tags$head(includeScript("google-analytics.js")),
11+
titlePanel("Tidy Up PBR Data", windowTitle = "Tidy Up Data"),
1612
sidebarLayout(
1713
sidebarPanel(
1814
fluidRow(
1915
column(7, fileInput(
20-
'file1',
16+
'datafile',
2117
'Choose data file to upload',
2218
accept = c(
2319
'application/x-zip-compressed',
20+
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
2421
'text/csv',
2522
'text/comma-separated-values',
2623
'text/tab-separated-values',
2724
'text/plain',
25+
'.xlsx',
2826
'.csv',
2927
'.tsv'
3028
)
@@ -36,6 +34,9 @@ shinyUI(fluidPage(
3634
)
3735
),
3836
tags$hr(),
37+
tags$p(
38+
"For plan text data formats:"
39+
),
3940
fluidRow(
4041
column(4, checkboxInput('header', 'Header', TRUE)),
4142
column(4, radioButtons(
@@ -69,32 +70,53 @@ shinyUI(fluidPage(
6970
textInput("organization", label = "Organization", value = "Organization"),
7071
textInput("department", label = "Department", value = "Department"),
7172
actionButton("send", label = "Send"),
72-
p("@email cerveny.j@czechglobe.cz")
73+
p(
74+
"@email cerveny.j@czechglobe.cz"
75+
)
7376
)
7477
))
7578
,
7679
width = 5
7780
),
7881
mainPanel(
82+
strong(textOutput("count")),
83+
br(),
84+
strong(textOutput("filename")),
85+
em(textOutput("filesize")),
86+
br(),
87+
textOutput("inputdim"),
88+
textOutput("processeddim"),
89+
width = 7
90+
)
91+
),
92+
fluidRow(
93+
column(
94+
3,
95+
tags$img(src = "img/Logo-CzechGlobe.jpg", alt = "CzechGlobe", height = 60, align = "top")
96+
),
97+
column(
98+
2,
99+
tags$img(src = "img/Logo-C4Sys.jpg", alt = "C4Sys", height = 40, align = "right")
100+
),
101+
column(
102+
1,
103+
br()
104+
),
105+
column(
106+
5,
79107
actionLink("help", label = "Help"),
80108
conditionalPanel(
81109
"input.help",
82110
p(
83-
"This tool was developed to simplify manipulation with untidy data generated by Photon Systems Instruments (PSI) photobioreactor sofware. The data uploaded to this tool are expected in CSV (or TSV) multi-column format, containig each column description in the first row. Most simple untidy data preparation procedure is to export data from the software in ODS format and then export last Data sheet as CSV file in Excel."
111+
"This tool was developed to simplify manipulation with untidy data generated by Photon Systems Instruments (PSI) photobioreactor sofware. The data uploaded to this tool are expected in Excel (.xlsx) or plain text tabular data CSV (or TSV) format."
112+
),
113+
p(
114+
"For PSI photobioreactor software expoerted data, the most simple untidy data preparation procedure is to export data from the software in ODS format and then either save the file as .xlsx Excel format or export the last sheet (Data) as CSV file."
84115
),
85116
p(
86-
"In general this tool can be used on any numeric data table, e.g. for large datasets averaging, etc."
117+
"In general this tool can be used on any numeric data table, e.g. for large datasets tidying up, averaging, etc."
87118
)
88-
),
89-
strong(textOutput("count")),
90-
br(),
91-
strong(textOutput("filename")),
92-
em(textOutput("filesize")),
93-
br(),
94-
textOutput("inputdim"),
95-
textOutput("processeddim")
96-
,
97-
width = 5
119+
)
98120
)
99121
)
100122
))

www/img/Logo-C4Sys.jpg

54.5 KB
Loading

www/img/Logo-CzechGlobe.jpg

55 KB
Loading

www/img/Logo-ISBE.jpg

695 KB
Loading

0 commit comments

Comments
 (0)