I am typing this from my laptop at home. The good news is that my control chart can udpate based on the contract order number. I still have yet to update it based on the variables, but it is still progress nonetheless. Now, I am trying to subset the data set by column. I was able to do it by row, so now I need to do it by column.
library(qcc)
library(shiny)
library(DT)
mydata <-read.csv("dummydata.csv")
variables <- 1:ncol(mydata)
names(variables) <- names(mydata)
equipment <- mydata[1:nrow(mydata), c("CON")]
ui <- fluidPage(
titlePanel("Control Charts"),
sidebarLayout(
sidebarPanel(
fileInput("file1", "Choose a file in CSV format", accept = c("text/csv", "text/comma-separated-values,text/plain",
".csv")
), #fileInput
hr(),
selectInput(inputId = "equip", label = "Contract Order Number:", choices = equipment), #selectInput
selectInput(inputId = "var", label = "Choose which variable you want to graph", choices = variables), #selectInput
############################
#Added by A. Coleman 20180225
br(),
actionButton("goButton", "Go!"),
p("Update your variables")
############################
), #sidebar panel
mainPanel(
plotOutput(outputId = "controlchart"),
dataTableOutput(outputId = "datachart")
) #main panel
) #sidebar layout
) #user interface
#movingRange <- function(data){
#mRange <- vector()
#if (!is.null(data))
#{
# for (num in data[C(2:nrow(data)),])
#{
# difference <- data[num] - data[num - 1]
# mRange <- c(mRange, difference)
# }
#mRange <- sum(mRange, na.rm = FALSE)
# mRange <- mRange / length(mRange)
#mRange <- abs(mRange)
#return(mRange)
#}
# else
#{
# return(0)
# }
#} #movingRange() function
server <- function(input, output, session) {
loadedFile <- reactive({
file <- input$file1
file
}) #loadedFile()
graph <- eventReactive(input$goButton, {
file <-loadedFile()
if(is.null(file))
{
#d <- data.frame(mydata$CON %in% input$equip, input$var)
d <-mydata[mydata$CON %in% input$equip,]
d <- subset(d, CON %in% input$equip)
#d <- subset(select = input$var)
}
else
{
d <-read.csv(file$datapath)
d <- file[file$CON %in% input$equp,]
d <- subset(d, CON %in% input$equip)
}
mr = 0 #movingRange()
mean = 0
UCL <- mean + 2.66*mr
LCL <- mean - 2.66*mr
#increments <- d[c(input$equip), c("JON")]
spcChart <- qcc(d, type = "xbar", title = "Xbar Chart", xlab = "Increments", ylab = "Value" ) #qcc
(warn.limits <- limits.xbar(spcChart$center, spcChart$std.dev, spcChart$sizes, 2))
plot(spcChart, restore.par = FALSE)
})#eventReactive
output$controlchart <- renderPlot({
graph()
}) #render plot
output$datachart <- DT::renderDataTable({
file <-loadedFile()
if(is.null(file))
{
d <-mydata
}
else
{
d <-read.csv(file$datapath)
}
d
}) #render data table
} #server function
shinyApp(ui = ui, server = server)
Sources Used:
http://stat.ethz.ch/R-manual/R-devel/library/base/html/substr.html
https://stackoverflow.com/questions/8395716/select-multiple-rows-conditioning-on-id-in-r
Comments
Post a Comment