This is it:
library(readxl)
library(tidyverse)
library(ggplot2)
library(shiny)
Datos <- read_excel("Datos.xlsx")
Datos$DIA <- as.factor(Datos$DIA)
ui <- fluidPage(titlePanel = "Gráfica Energía",
fluidRow(sidebarLayout(
sidebarPanel(
helpText("Seleccionar el año y mes que se desea observar"),
selectInput("Año", h3("Año"),
choices = list("2014"=2014, "2015"=2015, "2016"=2016, "2017"=2017,
"2018"=2018, "2019"=2019, "2020"=2020)),
selectInput("Mes", h3("Mes"),
choices = list("Enero"=1, "Febrero"=2, "Marzo"=3,
"Abril"=4, "Mayo"=5, "Junio"=6,
"Julio"=7, "Agosto"=8, "Septiembre"=9,
"Octubre"=10, "Noviembre"=11, "Diciembre"=12))
),
mainPanel(
plotOutput("Grafico_Linea")
)
),
fluidRow(mainPanel(
plotOutput("Grafico_Box")
))
)
)
server <- function(input, output) {
output$Grafico_Linea <- renderPlot({
Datos %>%
filter(AÑO == input$Año, MES == input$Mes) %>%
ggplot() +
geom_line(aes(x = hora, y = VILLRAGU01, color = DIA), size = 1) +
labs(x = "Hora", y = "Energía [MWh]") +
scale_y_continuous(breaks = seq(0,25,5)) +
scale_x_continuous(breaks = seq(0,24,1)) +
theme_bw()
})
output$Grafico_Box <- renderPlot({
Datos %>%
filter(AÑO == input$Año, MES == input$Mes) %>%
ggplot() +
geom_boxplot(aes(x = DIA, y = VILLRAGU01, color = DIA)) +
labs(x = "Día", y = "Energía [MWh]") +
scale_y_continuous(breaks = seq(0,25,5)) +
theme_bw()
})
}
shinyApp(ui = ui, server = server)