library(shiny)
library(ggplot2)
library(lubridate)
library(tree)
library(tidyr)
# Reads data frames
sergio_train_plot <- readRDS("data/sergio_train_plot.RDS")
sergio_test_plot <- readRDS("data/sergio_test_plot.RDS")
shinyServer(function(input, output, session) {
# Choses one dataframe according to a selectInput in ui.R
data_plot <- reactive({
switch(input$user,
"Sergio (train)" = sergio_train_plot,
"Sergio (test)" = sergio_test_plot
)
})
# Creates a reactive slider that lets the user to choose max and min datetimes to plot
output$reacSlider <- renderUI({
mindate = min(round.POSIXt(data_plot()$datetime - 30*60, "hour"))
maxdate = max(round.POSIXt(data_plot()$datetime + 30*60, "hour"))
sliderInput("periodo", "Periodo",
min = mindate , max = maxdate,
value = c(mindate, maxdate),
step = 3600,
width = "80%")
})
time_margins <- reactive({
input$periodo
})
output$plot1 <- renderPlot({
t1 <- time_margins()[1]
t2 <- time_margins()[2]
plot_dataset <- data_plot()
dataset1 <- plot_dataset[plot_dataset$datetime > t1 & plot_dataset$datetime < t2,]
ggplot(data = dataset1) +
geom_line(aes(x = datetime, y = rssi, colour = wp), size=.5) +
ylim(-100, -20) +
theme(plot.title=element_text(vjust = -2.5)) +
theme(axis.title.x=element_blank(),
axis.title.y=element_blank()) +
labs(colour="Wall Plug:") +
geom_rect(aes(xmin=datetime-30, xmax=datetime+30, ymin=-100, ymax=-97, fill=factor(patron))) +
labs(fill="Patrón:")# + scale_fill_discrete(labels=c(1:12))
})
output$plot2 <- renderPlot({
t1 <- time_margins()[1]
t2 <- time_margins()[2]
plot_dataset <- data_plot()
dataset1 <- plot_dataset[plot_dataset$datetime > t1 & plot_dataset$datetime < t2,]
ggplot(data = dataset1) +
geom_line(aes(x = datetime, y = rssi, colour = wp), size=.5) +
ylim(-100, -20) +
theme(plot.title=element_text(vjust = -2.5)) +
theme(axis.title.x=element_blank(),
axis.title.y=element_blank()) +
labs(colour="Wall Plug:") +
geom_rect(aes(xmin=datetime-30, xmax=datetime+30, ymin=-100, ymax=-97, fill=factor(prediccion))) +
labs(fill="Predicción")
})
})