Max Mendez L
10.08.2020
When running the app, please give 4-5 seconds for the plot to show. The dataset is too big and takes a bit of time. Select one of the two examples provided. <!–html_preserve–>
Here it calculates, filter, and transfor the data to give a new plot without noise.
library(shiny)
library(ggplot2)
library(plyr)
library(dplyr)
library(plotly)
library(forecast)
shinyServer(function(input, output) {
Data <- reactive({
if (input$Control == "Control")
{
return(Control)
}
else
{
return(Experiment)
}
})
output$Plot1 <- renderPlot({
if ( input$Control == "Control") {
ggplot(Data(), aes(x = Control$V1, y=Control$V2)) + theme_classic() + xlim(25,30) +
geom_line()
} else {
if ( input$Control != "Control") {
ggplot(Data(), aes(x = Experiment$V1, y=Experiment$V2)) + theme_classic() + xlim(25,30) +
geom_line() }
}
output$Filtered <- if ( input$Control == "Control") {
x=Control$V1
y=Control$V2
fit<- smooth.spline(Control$V1,Control$V2,all.knots = T)
smooth<-as.numeric(predict(fit,x)$y)
data.detrend <- detrend(smooth, tt = 'linear')
data.detrend <- ts(as.numeric(data.detrend),
start=c(first(data.detrend),1), frequency=10000)
decomposed<- decompose(data.detrend) # decompose time series to extract the trend
data.detrend<-decomposed$x - decomposed$trend
data.detrend<-data.detrend - decomposed$seasonal
plot(data.detrend, xlim=c(5,6), ylim=c(-3,3))
} else {
if (input$Control != "Control") {
x=Experiment$V1
y=Experiment$V2
fit2<- smooth.spline(Experiment$V1,Experiment$V2,all.knots = T)
smooth2<-as.numeric(predict(fit2,x)$y)
data.detrend2 <- detrend(smooth2, tt = 'linear')
data.detrend2 <- ts(as.numeric(data.detrend2),
start=c(first(data.detrend2),1), frequency=10000)
decomposed2<- decompose(data.detrend2) # decompose time series to extract the trend
data.detrend2<-decomposed2$x - decomposed2$trend
data.detrend2<-data.detrend2 - decomposed2$seasonal
data.detrend2<- na.omit(data.detrend2)
plot(data.detrend2, xlim=c(5,6), ylim=c(-3,3))
}}
})
})
Example plot with Input