No Progress Today


   I forgot to write a blog post last class. I went down to practice the Elgar concerto. I have to record the whole concerto in a month for a competition. I have all the notes down, but I need to make it performance-ready. Hopefully it goes well. Ok, now for today's post.


   Today, I am trying to add control limits to the graph. For some reason, the graph is not updating when the variable changes. I didn't get to fix those problems today, but I will work more on it and see what I can do.



library(qcc)
library(shiny)
library(ggplot2)
library(dplyr)



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")
      ),
     
      #selectInput(inputId = "graphTypes", label = "Chose your qcc chart", choices = c("xbar")),
      numericInput(inputId = "group", label = "Size", value = 61, min = 1, step = 1),
     
      numericInput(inputId = "threshold", label = "Threshold value", value =0, min = 0, step = .25 ),
      numericInput(inputId = "numsigmas", label = "Choose Number of Sigmas you want", value = 3, min = 1,
                   step = 1),
     
      numericInput(inputId = "target", label = "Choose your Target Value", value = 10 ),
     
      uiOutput('vars')
    ),
   
   
   
    mainPanel(
     
      plotOutput(outputId = "controlchart")
     
   
     
    )
    )
  )


 



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$controlchart <- renderPlot({
    file <-loadedFile()
   
    if(is.null(file))
    {
      d <-mydata
    }
    else
    {
      d <-read.csv(file$datapath)
    }
   
    data(d)
    attach(d)
 
   
    y <- input$var
    d <- d%>% select_(.dots = list(y = y))
   
    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, nsigmas = input$numsigmas)
    (warn.limits <- limits.xbar(spcChart$center, spcChart$std.dev, spcChart$sizes, 2))
   
    abline(h = warn.limits, lty = 3, col = "chocolate")
   
 
   
   
 
   
   
 })
 


}

shinyApp(ui = ui, server = server)








Sources Used
https://www.rdocumentation.org/packages/graphics/versions/3.4.3/topics/plot

https://www.r-bloggers.com/producing-a-control-chart-in-r-an-application-in-analytical-chemistry/

https://www.rdocumentation.org/packages/qcc/versions/2.6/topics/qcc

https://cran.r-project.org/web/packages/qcc/qcc.pdf

Comments