...
 
Commits (2)
shinyServer(function(input, output, session) {
output$zone_selection <- renderUI({
zones = readxl::read_xlsx(paste0('', input$result_xls), sheet = 'LMP') %>%
names()
names() %>% str_sort()
selectInput('zone', 'Choose the zone:',
choices = zones[-1])
})
output$hpp_selection <- renderUI({
zones = hrgen = readxl::read_xlsx(paste0('', input$result_xls), sheet = 'Hydro power generation') %>%
names() %>% str_sort()
selectInput('hpp', 'Choose the hydro-power plant:',
choices = hrgen[-1])
})
output$main_plot <- renderPlot({
res = readxl::read_xlsx(paste0('', input$result_xls), sheet = 'Reservoirs') %>%
......@@ -220,63 +226,52 @@ shinyServer(function(input, output, session) {
else if (input$plot_type == 'res_single') {
inflows = readxl::read_xlsx(paste0('', input$result_xls), sheet = 'Inflows') %>%
select(contains(paste0(input$zone, '_HPHS')),
contains(paste0(input$zone, '_HDAM'))) %>%
select((input$hpp)) %>%
mutate(date = seq(as_datetime('2016-01-01'), by = 'day', length.out = n())) %>%
mutate(day_of_the_year = yday(date)) %>%
gather(area, inflow, -date, -day_of_the_year)
spillage = readxl::read_xlsx(paste0('', input$result_xls), sheet = 'Spillage') %>%
select(contains(paste0(input$zone, '_HPHS')),
contains(paste0(input$zone, '_HDAM'))) %>%
select((input$hpp)) %>%
mutate(date = seq(as_datetime('2016-01-01'), by = 'day', length.out = n())) %>%
mutate(day_of_the_year = yday(date)) %>%
gather(area, spillage, -date, -day_of_the_year)
discharge = readxl::read_xlsx(paste0('', input$result_xls), sheet = 'Water discharge') %>%
select(contains(paste0(input$zone, '_HPHS')),
contains(paste0(input$zone, '_HDAM'))) %>%
select((input$hpp)) %>%
mutate(date = seq(as_datetime('2016-01-01'), by = 'day', length.out = n())) %>%
mutate(day_of_the_year = yday(date)) %>%
gather(area, discharge, -date, -day_of_the_year)
pumping = readxl::read_xlsx(paste0('', input$result_xls), sheet = 'Pumping') %>%
select(contains(paste0(input$zone, '_HPHS')),
contains(paste0(input$zone, '_HDAM'))) %>%
select((input$hpp)) %>%
mutate(date = seq(as_datetime('2016-01-01'), by = 'day', length.out = n())) %>%
mutate(day_of_the_year = yday(date)) %>%
gather(area, pumping, -date, -day_of_the_year)
res_zone = select(res, date, contains(paste0(input$zone, '_HPHS')),
contains(paste0(input$zone, '_HDAM'))) %>%
res_zone = select(res, date, contains(input$hpp)) %>%
mutate(day_of_the_year = yday(date)) %>%
gather(area, level, -date, -day_of_the_year)
gen_zone = select(gen, date, contains(paste0(input$zone, '_HPHS')),
contains(paste0(input$zone, '_HDAM'))) %>%
gen_zone = select(gen, date, contains(input$hpp)) %>%
mutate(day_of_the_year = yday(date)) %>%
gather(area, generation, -date, -day_of_the_year)
res_normalised = res_zone %>% group_by(area) %>% mutate(max_level = max(level)) %>% ungroup() %>% mutate(norm_level = level / max_level) %>% select(date, day_of_the_year, area, norm_level)
merged = inner_join(
inner_join(
inner_join(
inner_join(
inner_join(
inner_join(inflows, res_zone), gen_zone),
spillage),
pumping),
discharge),
res_normalised) %>%
inner_join(inflows, res_zone), gen_zone),
spillage),
pumping),
discharge) %>%
# mutate(filling_rate = (inflow * 60 * 60 * 24 / 1e6) / level) %>%
mutate(diff_level = c(NA, diff(level))) %>%
mutate(outflow = discharge + spillage) %>%
gather(variable, output, -date, -day_of_the_year, -area)
if (length(unique(res_zone$area) < 2)) {
merged = merged %>% filter(variable != 'norm_level')
}
if (all(is.na(merged %>% filter(variable == 'pumping') %>% pull(output)))) {
merged = merged %>% filter(variable != 'pumping')
}
......@@ -316,9 +311,32 @@ shinyServer(function(input, output, session) {
# ylab('GWh/day') +
theme(axis.text.x = element_text(size = 8, angle = 45, hjust = 1),
legend.position = 'bottom')
print(g)
# Hydro power generation ---------------------------------------------------------------------------------
} else if (input$plot_type == 'hydro_gen') {
hrgen_y = hrgen %>%
select(-X__1) %>%
gather(plant, generation, -date) %>%
mutate(year = lubridate::year(date)) %>%
group_by(year, plant) %>%
summarise(generation = sum(generation)) %>%
ungroup() %>%
separate(plant, c('Country', 'Type', 'Name'), remove = FALSE)
g = ggplot(hrgen_y, aes(x = fct_reorder(plant, generation, .desc = TRUE) ,
y = generation,
fill = Type)) +
geom_bar(stat = 'identity') +
geom_label(aes(label = round(generation)), color = 'white') +
facet_wrap(~year, ncol = 1) +
xlab('Hydro-power plant') +
theme_light() +
theme(axis.text.x = element_text(size = 12, angle = 90, hjust = 1))
print(g)
# Power flows ---------------------------------------------------------------------------------
} else if (input$plot_type == 'pf') {
}else if (input$plot_type == 'pf') {
this_pf = pf %>%
select(-X__1) %>%
......@@ -341,7 +359,7 @@ shinyServer(function(input, output, session) {
legend.position = 'none')
print(g)
}
}
})
})
\ No newline at end of file
......@@ -36,13 +36,17 @@ shinyUI( fluidPage(
'power flows' = 'pf')),
checkboxInput('middle_year', 'Show only middle period', value = FALSE),
conditionalPanel(
condition = "input.plot_type == 'gen_mix' || input.plot_type == 'res_single'",
condition = "input.plot_type == 'gen_mix'",
uiOutput("zone_selection")
),
conditionalPanel(
condition = "input.plot_type == 'awv'",
checkboxInput("check_logscale", label = "Log10 y-axis", value = TRUE),
numericInput("num_maxhwm", label = h3("Max shown value"), value = 1000)
),
conditionalPanel(
condition = "input.plot_type == 'res_single'",
uiOutput("hpp_selection")
)
......