I have been working on this most of the day and have it down to this and not sure where to go.
The last error(s) that I get is on the display of the shinyApp with SC120C not found.
I am positive the paths are correct and so are the file names. This code was originally written in as nonshiny script and it works exactly as expected. I am have only been coding for about 3 weeks so I know my code is clunky and amateurish but I have to start somewhere. This app is only on my computer so its not going out on the web its just for me to move the graphs back and forth to overlay them which I need to figure out how to get the timeoffset into the time_ns caculation too but that's another day.
library(shiny)
library(stringr)
library(dplyr)
library(ggplot2)
library(zoo)
library(DT)
library(tokenizers)
setwd ("E:/Updated_Datasets_20190603/SC106/")
datasets1 <- list("DS01", "DS02","DS03","DS04", "DS05", "DS06", "DS07", "DS08", "DS09", "DS10", "DS11",
"DS12", "DS13", "DS14" )
datasets2 <- list("Pulser_DS1", "Pulser_DS2",
"Pulser_DS3","Pulser_DS4", "Pulser_DS5", "Pulser_DS6", "Pulser_DS7",
"Pulser_DS8", "Pulser_DS9", "Pulser_DS10", "Pulser_DS11",
"Pulser_DS12", "Pulser_DS13", "Pulser_DS14" )
ui <-fluidPage(
titlePanel (title= h4("Display of the Data Set vs LTSpice Simulation")),
sidebarLayout(
sidebarPanel(
selectInput( inputId = "dataset1", label= "1. Choose a DataSet for analysis:", choices = c(datasets1 )),
selectInput( inputId = "dataset2", label= "2. Choose Pulser Dataset for analysis:", choices = c(datasets2 )),
sliderInput("timeOffset", "TimeOffset", min=-500, max= 500,
value = 0, step = 100),
# Input: Specification of range within an interval ----
sliderInput("range", "Range:",
min = 1, max = 1000,
value = c(200,500))
),
mainPanel(
plotOutput ("myplot")
)
)
)
server <- function(input, output){
SC120000 <- renderTable({
req(input$dataset1)
SC120000[[input$dataset1]]
SC120 <-as.data.frame(SC120000)
SC120C <-SC120%>%
mutate(time_ns = ((Time)*(1.0e9)))
# The Pulser is on channel of SC120 the other correction factors are commented out as they are needed for
#other SCopes and matrix data
SC120C %>%
summarise(matrixCh1Datacf <- mean(Channel1_Voltage), # The correction factor for theMatrix Data Channel Pulser voltage if needed
matrixCh2Datacf <- mean(Channel2_Voltage),
tenPecentminch1voltage <- (0.10*min(Channel1_Voltage)), # calculate rise 10% min
ninetyPercentmaxch1voltage <- (0.90*max(Channel1_Voltage)),
tenPecentminch1voltage <- (0.10*min(Channel2_Voltage)), # calculate rise 10% min
ninetyPercentmaxch1voltage <- (0.90*max(Channel2_Voltage)), #Calculate rise time 90% max
matrixCH1dT <<- (time_ns[2]-time_ns[1])*1000)
# The corrected Ch1 voltage
Channel2_Average<-as.vector( rollapply(SC120000$Channel2_Voltage, FUN= mean, width=18, na.rm=FALSE))
# a rolling average for smoothing the graph
Channel2_Average=append(Channel2_Average, c(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0), after= length(1))
# Some of the values are lost when rolling average is applied added back for concatinating vector to datafram
Channel2_Average[1] <- 0
Channel2_Average<-as.data.frame(Channel2_Average)
Channel2_Average <-cbind(SC120000$time_ns, Channel2_Average)
colnames(Channel2_Average)[1] <- "time_ns"
SC120C<- inner_join(Channel2_Average,SC120C) # this joins the frames
SC120C <-as.data.frame(SC120C)
})
Pulser <- renderTable({
req(input$dataset2)
Pulser[[input$dataset2]]
PulserC <-as.data.frame(Pulser)
colnames(Pulserc) <- c("Time", "Voltage") #naming columns 1 and 2 in Pulser1
PulserD <- PulserC %>%
mutate(time_ns = ((Time)*(1.0e9))) #dplyr converts time to nanosec
colnames(PulserD)[3] <- "time_ns"
# Pulserfile <- Pulserfile %>% mutate(Voltage = ((Voltage)*1.5))
#dplyr converts time to nanosec
PulserD %>%
summarise(
LTSpicedatacf <- (mean(Voltage)), # The correction factor for the LTSPICE Pulser voltage
tenPecentminLTSPICEvoltage <- (0.10*min(Voltage)), # 10% of the minimum voltage
ninetyPercentmaxLTSPICEvoltage <- (0.90*max(Voltage)), # 90% of the max voltage
LTspicePulserdT <- (time_ns[2]-time_ns[1])*1000 # change in time for first row to second
)
#Pulser Correction factor
PulserD <-PulserD %>%
mutate(LTspice_Corrected =(Voltage-LTSpicedatacf)) # The corrected LTSpice votage which must be o
# plots graph of Pulser 4.1 LTSpice raw data
})
#Pulser <- Pulser %>% #there is leading and trailing data that must removed from the data frame for better resolution
# filter( time_ns > 0 ) %>%
# select ( Voltage,time_ns, LTspice_Corrected)
#SC120000<- SC120000%>% #there is leading and trailing data that must removed from the data frame for better resolution
# filter( time_ns > 0 & time_ns< 2200)%>%
# select(time_ns, Channel2_Average, Channel2_Voltage)
output$myplot<-renderPlot({
myplot<- ggplot() +
geom_line(data=SC120C, aes(x=time_ns, y=Channel2_Average), na.rm = TRUE)+
geom_line(data=PulserD, aes(x=time_ns, y= LTspice_Corrected))+
theme_bw()
print (myplot)
})
}
shinyApp(ui,server)
`````r