-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.R
84 lines (62 loc) · 2.51 KB
/
server.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
#
# This is the server logic of a Shiny web application. You can run the
# application by clicking 'Run App' above.
#
# Find out more about building applications with Shiny here:
#
# http://shiny.rstudio.com/
#
library(shiny)
library(ggplot2)
smoothDerivative <- function(x, y){
spl <- smooth.spline(x, y)
pred.prime <- predict(spl, deriv=1)
return(pred.prime$y)
}
# Define server logic required to draw a histogram
shinyServer(function(input, output) {
output$distPlot <- renderPlot({
file <- read.csv(paste("logs/",input$fileName, sep=""), header=TRUE)
file <- head(file[c(1,which(rowSums(diff(as.matrix(file[,grep('time',names(file))])))!=0)+1),],-1)
logNames <- names(file)
logTimes <- file[-1,1]
#Estimate acceleration based on velocity
predicted <- tryCatch(
{
leftAccel <- smoothDerivative(file$time, file$left.velocity)
rightAccel <- smoothDerivative(file$time, file$right.velocity)
},
error=function(cond){
message(cond)
return()
}
)
lAdjusted <- subset(file, leftAccel < input$accelThreshold)
rAdjusted <- subset(file, rightAccel < input$accelThreshold)
#Calculates standard deviation of error of remaining data.
lStandard <- sd(lAdjusted$left.error)
rStandard <- sd(rAdjusted$right.error)
#Estimate expected values based on inputted constants, velocity, and estimated acceleration
# lExpectedVolt <- file$Drive.left_vel*input$velConst + leftAccel*input$accelConst + input$voltConst
# rExpectedVolt <- file$Drive.right_vel*input$velConst + rightAccel*input$accelConst + input$voltConst
#Calculate residuals
# lResid <- (lExpectedVolt - file$Drive.left_voltage)^2
# rResid <- (rExpectedVolt - file$Drive.right_voltage)^2
# get data based on input$dataVal from ui.R
xData <- logTimes
yData <- file[-1, input$dataVal]
# if (is.element(input$dataVal,c("left.error","right.error"))) {
#
# }
# else {
# yData <- file[-1, input$dataVal]
# }
name <- input$dataVal
curData <- data.frame(xData, yData)
# draw plot with specified data values
if (input$plotType == "scatter"){plot <- ggplot(data=curData, aes(x=xData, y=yData)) + geom_point() + labs(x = "Time", y = name)}
else{(plot <- ggplot(data=curData, aes(x=xData, y=yData)) + geom_line() + labs(x = "Time", y = name))}
if(input$smooth == TRUE){plot <- plot + geom_smooth(method="loess",span=input$span)}
plot
})
})