-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.R
81 lines (50 loc) · 2.38 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
shinyServer(function(input, output, session) {
# selections filters for Browse Data Page
selectedBrowseTable = selectedBrowseData(input, output, session)
output$tableData = renderDataTable({selectedBrowseTable()})
# Export csv
output$exportBrowse = exportBrowseData(input, output, session, selectedBrowseTable)
# Use both inputs for each dimension
combineBrowseInputs(input, output, session)
# Selection filter for SUA page
selectedSUAtable = selectedSUAData(input, output, session)
output$tableSUA = renderTable({selectedSUAtable()})
output$suaTitle = renderText({SUATitle(input, output, session)})
# input/output tables for SUA elements
individualSUATables = makeWideSuaDataTables(input, output, session, suaAreaYear, productionUploadTable)
renderSUATables(input, output, session, individualSUATables)
# save & continue buttons
observeSequentiallyActive(input, output, session)
# save data back to database and restore default data
observeSaveRestore(input, output, session)
# plots
output$suaPlot = renderPlot({SUAPlot(input, output, session, selectedSUAtable, productionUploadTable)})
output$productionPlot = renderDygraph({
if(!is.null(input$tableProduction)){
ts = data.table(hot_to_r(input$tableProduction))
}else{
ts = individualSUATables()$Production
}
itemName = ts[as.numeric(input$tableProduction_select$select$r), Item]
tsData = ts[as.numeric(input$tableProduction_select$select$r), -c("measuredItemCPC", "Item"), with = F]
tsDataLong = data.table( Year = names(tsData), Production = unlist(list(tsData[1, 1:ncol(tsData), with = F])))
names(tsDataLong) = c("Year", "Production")
tsDataLong[, Year := unlist(tstrsplit(Year, "[", fixed = T)[2])]
tsDataLong[, Year := unlist(tstrsplit(Year, "]", fixed = T))]
tsDataLong[, Year := as.Date(as.character(Year), format = '%Y')]
tsPlot = xts(tsDataLong, order.by = tsDataLong$Year )
dygraph(tsPlot, main = paste(itemName))
})
# Upload Production Data
productionUploadTable = reactive({
inFile = input$productionUpload
if (is.null(inFile))
return(NULL)
as.data.table(read.csv(inFile$datapath, header = input$header,
sep = input$sep, quote = input$quote)
)
})
output$productionUploadTable <- renderTable({
productionUploadTable()
})
})