Debugging

Technically, I finished the first draft of the app yesterday after school. However, I am getting an error in my program that I cannot understand. The error doesn't originate in my code but in a match.arg script. It says:

Loading required package: shiny
Error in match.arg(position) : 'arg' must be NULL or a character vector

I am also getting a message that says "Debug location is approximate because the source is not available." I wonder if it is coming from my data set. Let me test that. That did not work.

It turns out it was a syntax error in the sidebarLayout function. I had the uiOutput() where the mainPanel() was supposed to be. I moved the uiOutput back into the sidebarPanel, and it fixed it. Then, I fixed a couple more syntax errors, mostly involving commas.


   Now, I need to get the server to work. My getVariableNames() reactive method is null. Not a surprise that it was from a syntax error. I had unnecessary parentheses.

   The app runs now, but the graph still is not showing up. I used the qcc package.

OH MY GOD THIS ACTUALLY WORKS!!!!!!!!!! OH MY GOD!!!!!! I NEARLY SCREAMED!!!!!!!!!!!!!!!!!!!!!!

Now, that I got the first draft of the app to work, I can modify it to work for different graphs. I will try to draw the limits on the graph. That is my first goal. I am having difficulties modifying the app, but I have a basic app down, so I am happy about that.







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", "R", "S","xbar.one", "p", "np", "c",
                                                                                     # "u", "g")),
      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),
     
      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
    {
      data <-read.csv(file$datapath)
    }
   
    stddev <- sqrt(input$threshold * (1 - input$threshold)/input$group)
    upperLimit <- input$threshold + 3*stddev
    lowerLimit <- input$threshold - 3*stddev
    #chart <-switch(input$graphTypes, norm = rnorm, unif = runif, lnorm = rlnorm, exp = rexp, rnorm) #modify to work for a control chart instead of a histogram
   
    spcChart <- qcc(d, type = "xbar", nsigmas = 3) #nsigmas = input$numsigmas
   
    process.capability(spcChart, spec.limits = c(upperLimit, lowerLimit))
   
   
 
   
   
 })
 


}

shinyApp(ui = ui, server = server)

Sources Used:
https://stackoverflow.com/questions/39967867/shiny-error-in-match-argposition-arg-must-be-null-or-a-character-vector

http://www.naklih.com/blog/?p=49

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

https://www.intrafocus.com/2014/07/xmr-chart/

https://stackoverflow.com/questions/40623749/what-is-object-of-type-closure-is-not-subsettable-error-in-shiny/40623750

https://stackoverflow.com/questions/29812633/cannot-coerce-type-closure-to-vector-of-type-character


Comments

  1. Nice one! It was a perfect guide for beginners. You nicely explain importance of XMR chart. Thanks

    ReplyDelete

Post a Comment