-
Notifications
You must be signed in to change notification settings - Fork 0
/
analyse.R
152 lines (130 loc) · 5.79 KB
/
analyse.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
analyseUI <- function(id, label = 'analyse'){
ns <- NS(id)
h3('Analysis')
shinyjs::useShinyjs()
fluidPage(
fluidRow(
shinydashboard::box(width = 3,
title = 'Time Series Control Panel', status = 'warning',
column(width = 6,
selectInput(inputId = ns('plan'),
label = 'Type of Plan',
choices = PLANS, selected = NULL),
selectInput(inputId = ns('h1'), choices = NULL,
label = NULL),
numericInput(inputId = ns('dollar1'),
label = "$/kWh Non-peak", value = 0,
min = 0, max = 10, step = 0.001)
),
column(width = 6,
selectInput(inputId = ns('planTier'),
label = 'Tier', choices = NULL,
selected = NULL),
selectInput(inputId = ns('h2'), choices = NULL,
label = NULL),
numericInput(inputId = ns('dollar2'),
label = "$/kWh Peak", value = 0,
min = 0, max = 10, step = 0.001)
),
column(width = 12,
uiOutput(outputId = ns('dateRange')),
selectInput(inputId = ns('aggLvl'),
label = "Aggregation Level",
choices = AGGCHOICE,
selected = AGGCHOICE[1]))
# fluidRow(
# column(width = 6,
# selectInput(inputId = ns('month'), label = 'Select Month',
# choices = month.name)),
# column(width = 6,
# selectInput(inputId = ns('compare'),
# label = 'Compare old data',
# choices = c('No', 'Last Month', 'Same Month Previous Years'))),
# selectInput(inputId = ns('type'), label = 'Type of Plan',
# choices = c('Basic', 'TOU'))
# ),
),
shinydashboard::box( width = 9,
title = 'Time Series Plot', status = 'warning',
shinycssloaders::withSpinner(
plotly::plotlyOutput(outputId = ns("tsplot"))
)
)
),
fluidRow(
shinydashboard::box(width = 3,),
shinydashboard::box(width = 9, title = 'Distribution Per Hour',
status = 'warning',
shinycssloaders::withSpinner(
plotly::plotlyOutput(outputId = ns("boxplot"))
))
)
)
}
analyseServer <- function(id, dt){
moduleServer(
id,
function(input, output, session){
observeEvent(input$plan,{
updateSelectInput(inputId = 'planTier', choices = TIER[[input$plan]])
})
observeEvent(input$planTier, {
if(names(TIER)[1] == input$plan){
lapply(c('h1','h2','dollar1','dollar2'), shinyjs::showElement,
animType = 'fade', anim = T)
updateSelectInput(inputId = 'h1', choices = 0:23,
selected = HOUR[[input$planTier]][1],
label = 'Start Hour')
updateSelectInput(inputId = 'h2', choices = 0:23,
selected = HOUR[[input$planTier]][2],
label = 'End Hour')
} else{
lapply(c('h1','h2','dollar1','dollar2'), shinyjs::hideElement,
animType = 'fade', anim = T)
}
})
observe({
output$dateRange <- renderUI({
req(dt())
ns <- session$ns
dateRangeInput(inputId = ns('dates'), label = 'Date Range',
start = min(dt()$dttm_start), end = max(dt()$dttm_start))
})
})
listen <- reactive({
list(input$dates)
})
observeEvent(listen(),{
validate(
need(!is.null(dt()), 'Require data'),
need(!is.na(input$dates[1]), 'Select a date range'),
need(!is.na(input$dates[2]), 'Select a date range')
)
df <- copy(dt())
df[, ':='(start = as.Date(dttm_start))]
df <- df[start >= input$dates[1] & start <= input$dates[2]]
output$tsplot <- plotly::renderPlotly({
plotly::ggplotly(
ggplot(data = df,
aes(x = hour, y = value))+
geom_line(aes(group = day2), alpha = 0.4)+
geom_smooth()+
theme_bw()+
labs(x ='Hour beginning' , y = 'kWh')+
scale_x_continuous(breaks = seq(0,23,by=3))
)
})
output$boxplot <- plotly::renderPlotly({
#browser()
plotly::ggplotly(
ggplot(data = df, aes(x = factor(hour), y = value))+
geom_boxplot()+
geom_jitter(aes(fill = factor(day)))+
labs(x ='Hour beginning' , y = 'kWh', fill = 'Day')+
theme_bw()
)
})
})
}
)
}