Learning How to Code Control Charts in RShiny

   Now that I've gotten more familiar with the RShiny package, I researched how to code a control chart  (or an x-bar chart) in that application. I came across a sample control chart RShiny application. I will use that as an example of how I want my application to look like.

   There is a package in R called "qcc". That package allows for creating x-bar charts in R. I can use both the "qcc" package and the "shiny" package to create an interactive control chart web application. There are two types of control charts: x-bar and range. X-bar charts show "how much variation exists in the process over time." Range (R) charts show "the variation within each variable(called 'subgroups)."

    USL (Upper Specification Limit) and LSL (Lower Specification Limit) are the limits of variation that the client wants. UCL and LCL show whether or not the process is in control.  But, we need to check to see if the control limits match the specification limits. The process capability index (Cpk)goes like this:
        " 1. First, find the difference between X-bar and LSL, and divide by 3*sigma.
           2. Next, find the difference between X-bar and USL, and divide by 3*sigma.
           3. Compare those two values, and pick the smaller one. That will be your Cpk.
                         -If Cpk >= 1.33, then the process is capable.
                         - If Cpk < 1.33, then the process is not capable. "

   This is how I would create an R chart.(rnorm creates subgroups) : 
      install.packages("qcc")
      library(qcc)
      variableName <- as.data.frame(replicate(# of measurements, rnorm(# of subgroups, mean=#, sd=#)))
      anotherVariable <- qcc(variableName, type="R", nsigmas=3)  #qcc() function creates the R chart


   Now, creating an x-bar chart (the qcc() function creates the x-bar chart):
       anotherVariable<- qcc(variableName, type="xbar", nsigmas=3)
   
   Then the "full process capability analysis:"
        process.capability(anotherVariable, spec.limits=c(LSL, USL))
 

  I'm just going to include this summary from the article just in case I need it later. It doesn't hurt to have another copy of the code:


"# Load your data FROM A CSV FILE with one subgroup per row 
my.data <- read.csv("my-data.csv",header=FALSE) 

# OR, Load your data for each subgroup MANUALLY: 
sg1 <- c(1.397742,1.399917,1.278918,1.279828)  # Fill in YOUR data! 
sg2 <- c(1.397742,1.399917,1.278918,1.279828)  # Fill in YOUR data! 
sg3 <- c(1.397742,1.399917,1.278918,1.279828) # Fill in YOUR data! 
# If you have more than one subgroup, include it in this list: 
my.data <- rbind(sg1,sg2,sg3) 

# Draw the R Chart and calculate relevant metrics 
q1 <- qcc(my.data, type="R", nsigmas=3) 

# Draw the X-Bar Chart and calculate relevant metrics 
q2 <- qcc(my.data, type="xbar", nsigmas=3) 
# Establish the LSL and USL as set by customer specs, then 
# draw the process capability chart and calculate metrics: 
lsl <- 1.31 # Fill in YOUR LSL here! 
usl <- 1.32 # Fill in YOUR USL here! 
process.capability(q2, spec.limits=c(lsl,usl)) "

I am currently typing this on my laptop. R is downloaded on my computer at home. I am going to plan how I want my code to look like. It will be subject to change later.

install.packages("qcc")
library(qcc)
library(shiny)

ui <- fluidPage(

      titlePanel("Control Charts"),

      sidebarLayout(
           sidebarPanel(
                  #choose the dataset
                  fileInput("file1", "Choose a file (Make sure it is in CSV                                  format.",
                           multiple = TRUE,
                           accept = c("text/csv", "text/comma-separated-values,                                       text/plain", ".csv"),
                  
                 
                 #choose amount of data shown on chart
                 sliderInput(inputId = "n", 
                              label = "Number of Equipment: ",
                              min = 1,
                              max = 100,
                              value = 61)
           ),

        mainPanel(
           
            #I would insert the code to make the x-bar and R charts here
           tableOutput("contents")     
               
            )
     )
            

)


server <- function(input, output){


}

shinyApp(ui = ui, server = server)


Sources Used:
https://www.r-bloggers.com/my-first-shiny-app-control-charts/

https://michy-apps.shinyapps.io/control_charts/

https://qualityandinnovation.com/2015/11/02/control-charts-in-r-a-guide-to-x-barr-charts-in-the-qcc-package/

https://qualityandinnovation.files.wordpress.com/2015/11/xbar-r-75-925_9.pdf

http://shiny.rstudio.com/images/shiny-cheatsheet.pdf

https://shiny.rstudio.com/articles/basics.html

https://shiny.rstudio.com/articles/upload.html


For Reference Later:

https://shiny.rstudio.com/tutorial/

Comments