This repository has been archived by the owner on Oct 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.R
79 lines (63 loc) · 2.44 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
library(googlesheets)
library(shiny)
library(ggplot2)
library(timeDate)
library(zoo)
#read and preprocess data
source('readAndPreProcessData.R')
shinyServer(
function(input, output) {
observeEvent(input$updateData, {
source('readAndPreProcessData.R')
})
#Dynamically set input date
output$dateControls <- renderUI({
dateRangeInput('financeDateRange',
'Временной промежуток для анализа',
start = minDateInData,
end = maxDateInData)
})
#Prepare subsets based on input date's
# dataToPlot <- reactive({
# plotData <- finance_combined[(finance_combined$date >= input$financeDateRange[1]) & (finance_combined$date <= input$financeDateRange[2]), ]
# plotData$cumulativeNetInflow <- cumsum(plotData$netInflow)
# return(plotData)
# })
dataToPlot <- reactive({
plotData <- finance_combined[(finance_combined$date >= input$financeDateRange[1]) & (finance_combined$date <= input$financeDateRange[2]), ]
plotData$cumulativeNetInflow <- cumsum(plotData$netInflow)
return(plotData)
})
#calculate data summeries
dataSummaries <- reactive({
plotData <- dataToPlot()
totals <- data.frame(sum(plotData$inflow), sum(plotData$outflow), sum(plotData$netInflow))
colnames(totals) <- c("inflow", "outflow", "netInflow")
daysInPeriod <- as.numeric(input$financeDateRange[2] - input$financeDateRange[1])
averages <- totals * (as.numeric(input$averagingPeriod) / daysInPeriod)
return(list(totals = totals, averages = averages))
})
#Plot Inflow/Outflow
output$transactions <- renderPlot({
ggplot(dataToPlot()) +
geom_bar(aes(date, netInflow, fill = transactionType), stat = "identity", position = "dodge") +
geom_line(aes(date, cumulativeNetInflow))
})
#sum totals and print them
output$summaryTotalsText <- renderText(
paste(
'Totals over the period from ',
input$financeDateRange[1],
' to ',
input$financeDateRange[2],
':',
sep = ''
)
)
output$summaryAverages <- renderTable({
dataSummaries()$averages
})
#Tut budut otdelnye grafiki dla nas dwoich + budet forma dla vvoda v tablicu. Nuzno prorabotat'
output$textPointer <- renderText( ' Продолжение следут, я замучалсяэ')
}
)