-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.R
94 lines (55 loc) · 2.1 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
################################# Server ######################################
library(plyr)
library(dplyr)
library(tidyr)
library(lubridate)
library(shiny)
library(readxl)
library(openxlsx)
library(rsconnect)
source('modify_template.r', local = TRUE)
shinyServer(function(input, output) {
# import_template <- loadWorkbook('import_template.xlsx')
# Input functions --------------------------------------------------------------
getData_caselist <- reactive({
caselist <- input$caselist
if(is.null(caselist))
return(NULL)
nms <- names(read_excel(caselist$datapath, n_max = 0))
ct <- ifelse(grepl("Date", nms), "date", "guess")
caselist <- suppressWarnings(
read_excel(caselist$datapath, sheet = 1,skip = 1, col_types = ct)
)
colnames(caselist) <- make.names(colnames(caselist))
return(caselist)
})
getData_import_template <- reactive({
import_template <- loadWorkbook('import_template.xlsx')
if(is.null(input$caselist))
return(NULL)
caselist <- getData_caselist()
subset <- get_subset(caselist, input)
import_template <- modify_attendance(import_template, subset, input)
import_template <- modify_suspensions(import_template, subset, input)
import_template <- modify_grades(import_template, subset, input)
return(import_template)
})
# UI Display Functions ---------------------------------------------------------
output$choose_school <- renderUI({
validate(
need(
input$caselist, "Please Upload ")
)
caselist <- getData_caselist()
schools <- caselist$Home.School
selectInput("school", "Select School", as.list(schools))
}
)
# Download Output Functions ----------------------------------------------------
output$download_import_template <- downloadHandler(
filename = paste("Q", as.character(input$quarter),"_metric_import_template.xlsx", sep = ''),
content = function(file) {
saveWorkbook(getData_import_template(), file, TRUE)
}
)
})