-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathserver.R
More file actions
51 lines (47 loc) · 1.71 KB
/
server.R
File metadata and controls
51 lines (47 loc) · 1.71 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
## --------
## server.R
## --------
library(rio)
library(shiny)
library(tools)
library(foreign)
make_sas_csv <- function(x, file, filesnames){
csv_file <- paste0(filesnames, '.csv')
sas_file <- paste0(filesnames, '.sas')
foreign::write.foreign(df = x,
datafile = csv_file,
codefile = sas_file,
package = 'SAS')
zip(zipfile = file, files = c(csv_file, sas_file))
}
shinyServer(
function(input, output){
output$download_data <- downloadHandler(
filename = function() {
name <- basename(file_path_sans_ext(input$infile$name))
paste0(name, '.', {
## handle sas double format
if ('sas_plus_csv' == input$output_format) 'zip'
else input$output_format
})
},
content = function(file) {
input_file <- input$infile
input_file_format <- tools::file_ext(input_file$name)
if (is.null(input_file))
return(NULL)
else {
db <- rio::import(file = input_file$datapath,
format = input_file_format)
if ('sas_plus_csv' != input$output_format)
rio::export(x = db,
file = file,
format = input$output_format)
else make_sas_csv(x = db,
file = file,
filesnames = basename(file_path_sans_ext(input$infile$name)))
}
}
)
}
)