), width = 10)
)),
# Underlying reactive codes based on user input
server = function(input, output) {
# Select data file to load
df <- reactive({
dfile <- input$datafile
req(dfile)
read.csv(file = dfile$datapath)})
# Remove invalid columns from the data set based on certain criteria
myval <- reactive({
req(df())
id1 <- unname(which(sapply(df(), is.numeric))) # Numeric
my_data <- subset(df(), select = c(id1))
withNA <- apply(my_data, 1, function(x) any(is.na(x)))
if(withNA){
id2 <- unname(which(sapply(my_data, is.na))) my_data <- subset(my_data, select = -c(id2))}
newcol <- ncol(my_data)
id3 <- NULL
for (i in 1:newcol){
if (my_data[1,i]-my_data[2,i])
{id3 <- append(id3, i)
}}
my_data <- subset(my_data, select = c(id3))
rowcount <- nrow(my_data)
my_values <- my_data[3:rowcount,]})
param <- reactive({
req(input$param)
param <- myval()[[input$param]]})
lolim <- reactive({
req(input$param)
lolim <- as.numeric(df()[1,][[input$param]])})
hilim <- reactive({
req(input$param)
hilim <- as.numeric(df()[2,][[input$param]])})
rval <- reactive({
req(input$param)
lolim <- as.numeric(df()[1,][[input$param]])
hilim <- as.numeric(df()[2,][[input$param]])
ave <- round(mean(myval()[[input$param]]),digits = 4)
stdev <- round(sd(myval()[[input$param]]), digits = 4)
cp <- round((hilim-lolim)/(6*stdev),digits = 4)
cpku <- round((hilim-ave)/(3*stdev),digits = 4)
cpkl <- round((ave-lolim)/(3*stdev), digits = 4)
q1 <- round(as.numeric(unlist(quantile(myval()[[input$param]])))[2], digits = 4)
q2 <- round(as.numeric(unlist(quantile(myval()[[input$param]])))[3], digits = 4)
q3 <- round(as.numeric(unlist(quantile(myval()[[input$param]])))[5], digits = 4)
list(ave,q1,q2,q3,stdev,cp,cpkl,cpku)
})
output$dt <- renderTable({
req(input$param)
df()})
output$paramSel <- renderUI({
req(df())
selectInput("param", "Test Parameter: ", colnames(myval()), multiple = T)})
output$bPlot <- renderUI({
req(df())
checkboxInput("showBP", "Display Boxplot", value = F)})
output$dynaplots <- renderUI({
req(input$param)
n <- length(input$param)
dynaplotlist <- lapply(1:n, function(j){
chartnum <- paste("charts", j, sep = "")
limnum <- paste("lim", j, sep = "")
avgnum <- paste("avg", j, sep = "")
stdvnum <- paste("stdv", j, sep = "")
cPnum <- paste("cP", j, sep = "")
cPknum <- paste("cPk", j, sep = "")
quartnum <- paste("quart", j, sep = "")
fluidRow(
column(8, plotOutput(chartnum)),
br(),
br(),
br(),
column(4, verbatimTextOutput(limnum)),
column(4, verbatimTextOutput(avgnum)),
column(4, verbatimTextOutput(stdvnum)),
column(4, verbatimTextOutput(cPnum)),
column(4, verbatimTextOutput(cPknum)),
column(4, verbatimTextOutput(quartnum)),
)})
do.call(tagList, dynaplotlist)
})
observe({
n <- length(input$param)
for (j in 1:n) {
local({
chartnum <- paste("charts", j, sep = "")
limnum <- paste("lim", j, sep = "")
avgnum <- paste("avg", j, sep = "")
stdvnum <- paste("stdv", j, sep = "")
cPnum <- paste("cP", j, sep = "")
cPknum <- paste("cPk", j, sep = "")
quartnum <- paste("quart", j, sep = "")
# Chart rendering
output[[chartnum]] <- renderPlot({
req(input$param)
mybin <- input$bin
dframe <- as.data.frame(myval())
# Histogram
hp <- ggplot(dframe, aes(param())) + geom_histogram(color= "darkslategray", fill="darkseagreen3", bins = mybin) +
theme(axis.title.y = element_blank(), axis.title.x = element_blank()) + ggtitle(colnames(myval()[input$param])) +
geom_vline(aes(xintercept=mean(param())), color="blue", linetype="dashed", size=1) +
geom_vline(data=dframe, aes(xintercept=lolim()), color="red", linetype="dashed", size=1) +
geom_vline(data=dframe, aes(xintercept=hilim()), color="red", linetype="dashed", size=1)
# Boxplot
bp <- ggplot(dframe, aes(param())) + geom_boxplot(color= "darkslategray", fill="darkseagreen3", outlier.color = "darkmagenta") +
theme(axis.title.y = element_blank(), axis.text.y = element_blank(), title = element_blank()) +
stat_boxplot(geom = 'errorbar', width=0.2, color="darkslategray") +
geom_vline(data=dframe, aes(xintercept=lolim()), color="red", linetype="dashed", size=1) +
geom_vline(data=dframe, aes(xintercept=hilim()), color="red", linetype="dashed", size=1)
# Align charts
if(input$showBP){
plot_grid(hp, bp, ncol = 1, align = "v", axis = "bt")}
else
{plot_grid(hp, ncol = 1, align = "v", axis = "bt")}
})
# Statistics summary rendering
output[[limnum]] <- renderText({
req(input$param)
paste("LIMITS Lower :", lolim(), " Upper :", hilim())})
output[[avgnum]] <- renderText({
req(input$param)
paste("MEAN :", rval()[1])})
output[[stdvnum]] <- renderText({
req(input$param)
paste("STD DEVIATION :", rval()[5])})
output[[cPnum]] <- renderText({
req(input$param)
paste("CP :", rval()[6])})
output[[cPknum]] <- renderText({
req(input$param)
paste("CPK Lower :", rval()[7], " Upper :", rval()[8])})
output[[quartnum]] <- renderText({
req(input$param)
paste("QUARTILES Q1 :", rval()[2], " Q2 :", rval()[3], " Q3 :", rval()[4])})
})
}})
}
)Enter code here...