-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.R
80 lines (67 loc) · 2.06 KB
/
server.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
# This is the server logic for a Shiny web application.
# You can find out more about building applications with Shiny here:
#
# http://shiny.rstudio.com
#
library(shiny)
library(dplyr)
library(rio)
library(DT)
# parser
source("cr_parse.R")
shinyServer(function(input, output, session) {
output$loaded <- reactive(0)
outputOptions(output, "loaded", suspendWhenHidden = FALSE)
observeEvent(input$submit, {
my_input <- reactive({
in_file <- input$file_xlsx
if(is.null(in_file))
return(NULL)
file.rename(in_file$datapath,
paste(in_file$datapath, ".xlsx", sep=""))
my_df <- readxl::read_excel(paste(in_file$datapath, ".xlsx", sep=""), 1)
source("apc_fetch.R")
apc_fetch(my_df) %>%
dplyr::as_data_frame()
})
# Download options
output$download_xlsx <- downloadHandler(
filename = function() {
paste0('data-monitoar', Sys.Date(), '.xlsx')
},
content = function(con) {
rio::export(my_input(), con)
}
)
output$table <- renderPrint(my_input())
output$download_csv <- downloadHandler(
filename = function() {
paste0('data-monitoar', Sys.Date(), '.csv')
},
content = function(con) {
rio::export(my_input(), con)
}
)
# Download buttons
output$download_button_xlsx <- renderUI({
if (!is.null(my_input())) {
tabsetPanel(
tabPanel("Log",
verbatimTextOutput("table")
),
tabPanel("Download",
tagList(
tags$h4("Download Options"),
tags$p("Microsoft Excel",
downloadButton("download_xlsx", "Microsoft Excel (.xlsx)",
class = "btn-success")),
tags$p("Comma-seperated value",
downloadButton("download_csv", "Comma-separated values (.csv)",
class = "btn-success"))
)
))
}
})
})
output$loaded <- reactive(1)
})