forked from Molmed/ExportR
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.R
72 lines (62 loc) · 2.35 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
library(projmanr)
shinyServer(function(input, output) {
connection <- function(){
RSQLServer::src_sqlserver("MS_SQL", file='sql.yaml', database = 'ProjectMan')
}
project_names <- reactive({
projects <-
sample_table(connection()) %>%
select(project_id) %>%
distinct() %>%
collect()
return(projects$project_id)
})
# Since we want dynamical generate the choices for the project selector
# this construction is used to render a `selectizeInput` ui component
# onto the 'projectselector' ui element.
output$projectselector <- renderUI(
selectizeInput(inputId = "project",
label = "Choose a dataset:",
choices = project_names(),
selected = NULL, multiple = FALSE,
options = list(
placeholder = 'Please select an option below',
onInitialize = I('function() { this.setValue(""); }')
))
)
datasetInput <- reactive({
fetch_information_for_project(connection(), input$project)
})
output$downloadData <- downloadHandler(
filename = function() {
paste(input$project, '.csv', sep='')
},
content = function(file) {
write.csv(datasetInput(), file)
}
)
output$downloadYearReportData <- downloadHandler(
filename = function() {
paste("projectdata", "_", input$year, ".csv", sep="")
},
content = function(file) {
connection <- RSQLServer::src_sqlserver("MS_SQL", file='sql.yaml', database = 'ProjectMan')
start_date <- paste(input$year, "-01-01")
end_date <- paste(input$year, "-12-31")
report.data <- fetch_aggregated_data_per_instrument_for_period(connection, start_date, end_date)
write.csv(report.data, file = file, row.names=FALSE)
}
)
output$downloadAggregatedData <- downloadHandler(
filename = function() {
paste("projectdata", "_", as.Date(input$dateRange[1]), "_", as.Date(input$dateRange[2]), ".csv", sep="")
},
content = function(file) {
connection <- RSQLServer::src_sqlserver("MS_SQL", file='sql.yaml', database = 'ProjectMan')
start_date <- input$dateRange[1]
end_date <- input$dateRange[2]
aggregated_data <- fetch_aggregated_data_per_instrument_for_period(connection, start_date, end_date)
write.csv(aggregated_data, file = file, row.names=FALSE)
}
)
})