Progress


   Good news! The graph is showing up with the control limits. The bad news is that the graph won't update depending on the variable. I was able to customize the control chart with different color lines.

   I decided to add a data table to my app. Unlike the control chart, I was able to get this done relatively quick. I used the DT package to help build the data table.

   Another update I'm adding to the app is allowing the user to include specification limits if they want to. For some reason, only the upper specification limit is showing up.


library(qcc)
library(shiny)
library(DT)





mydata <-read.csv("dummydata.csv")




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")
      ),
   
      numericInput(inputId = "target", label = "Choose your Target Value", value = 10 ),
      numericInput(inputId = "group", label = "Size", value = 60, min = 1, step = 1),
   
   
      numericInput(inputId = "numsigmas", label = "Choose Number of Sigmas you want", value = 3, min = 1,
                   step = 1),
   
   
      wellPanel(
        checkboxGroupInput(inputId = "checkbox", label = "Specification Limits?",
                           choices = c("LSL","USL")),
        conditionalPanel(condition = "output.LSL == true",
                         numericInput(inputId = "lsl", label = "Lower Specification Limit", value = 1, min = 1, step = 1)
                         ),
        conditionalPanel(condition = "output.USL == true",
                         numericInput(inputId = "usl", label = "Upper Specification Limit", value = 1, min = 1, step = 1)
     
        )
      ),

      uiOutput('vars')
    ),
 
 
 
    mainPanel(
   
      plotOutput(outputId = "controlchart"),
      dataTableOutput(outputId = "datachart")
   
   
   
   
   
    )
    )
  )






server <- function(input, output) {



  loadedFile <- reactive({
    file <- input$file1
    file
  })

  getVariableNames <- reactive({
    file <- loadedFile()
    if (is.null(file))
    {
   
      varName <-names(mydata)
    }
    else
    {
      varName <- names(read.csv(file$datapath))
   
    }
  })

  output$vars <-renderUI({
    choices <- getVariableNames()
    selectInput(inputId = "var", label = "Choose which variable you want to graph", choices = choices)
  })


output$LSL <- reactive({
  numericInput(inputId = "lsl", label = "Lower Spec Lim", value = 1, min = 1, step = 1)

})

output$USL <- reactive ({
  numericInput(inputId = "usl", label = "Upper Spec Lim", value = 1, min = 1, step = 1)

})

  outputOptions(output, "LSL", suspendWhenHidden = FALSE)
outputOptions(output, "USL", suspendWhenHidden = FALSE)


  output$controlchart <- renderPlot({
    file <-loadedFile()
 
    if(is.null(file))
    {
      d <-mydata
    }
    else
    {
      d <-read.csv(file$datapath)
    }
 
 
 
   # stddev <- sqrt(input$threshold * (1 - input$threshold)/input$group)
    #upperLimit <- input$threshold + 3*stddev
    #lowerLimit <- input$threshold - 3*stddev
 
 
 

     spcChart <- qcc(d, type = "xbar", sizes = input$group, center = input$target, title = "Xbar Chart", nsigmas = input$numsigmas)
   
     (warn.limits <- limits.xbar(spcChart$center, spcChart$std.dev, spcChart$sizes, 2))
     plot(spcChart, restore.par =  FALSE)
 
    abline(h = warn.limits, lty = 3, col = "blue")
    #process.capability(spcChart, spec.limits = c() )
 
 })

  output$datachart <- DT::renderDataTable({
 
    file <-loadedFile()
 
    if(is.null(file))
    {
      d <-mydata
    }
    else
    {
      d <-read.csv(file$datapath)
    }
    d
  })



}

shinyApp(ui = ui, server = server)















Sources Used:

http://www.sthda.com/english/wiki/abline-r-function-an-easy-way-to-add-straight-lines-to-a-plot-using-r-software

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

https://rpubs.com/jamesonmarriott/239508

https://shiny.rstudio.com/tutorial/written-tutorial/lesson3/

https://stackoverflow.com/questions/34115076/shiny-app-checkboxinput-and-conditionalpanel

https://shiny.rstudio.com/reference/shiny/0.11/conditionalPanel.html

https://shiny.rstudio.com/articles/dynamic-ui.html

https://shiny.rstudio.com/reference/shiny/latest/checkboxGroupInput.html

Comments