Today, I installed R and RStudio on one of the school computers so that I would be able to work on the shiny application during thesis.
I finished the basics of the user interface. It has a file input button and a numeric input button. I will add more to it later. I just need to code the server to output a control chart, and then I will add more to it.
In the server function, I created a reactive expression to update the standard deviation and control limits whenever the input changes. From that, I created two variables for the upper control limit and the lower control limit.
I referenced source code of an already-made control chart because I need a reference for building the server function for my own control chart. Here is my code so far:
library(qcc)
library(shiny)
mydata <-read.csv("dummydata.csv", header = FALSE)
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 = "plot", label = "Choose a control chart", choices = c("Xbar", "Range"), multiple = FALSE),
numericInput(inputId = "group", label = "Size", value = 61, min = 1, step = 1),
numericInput(inputId = "dev", label = "Threshold value", value =0, min = 0, step = .25 )
),
uiOutput('vars'),
mainPanel(
plotOutput(outputId = "controlchart")
)
)
)
server <- function(input, output) {
createLimits <- reactive({
stddev <- sqrt(input$dev * (1 - input$dev)/input$group)
upperLimit <- input$dev + 3*stddev
lowerLimit <- input$dev - 3*stddev
})
output$controlchart = renderPlot({
y <-
spc_data <- control_chart(type = input$plot, data = null, group = input$group, n_sigma = stddev)
spcChart = plot_chart(plot_data = spc_data, plot_type = input$plot, var_name = y)
})
}
shinyApp(ui = ui, server = server)
Sources Used
https://shiny.rstudio.com/tutorial/written-tutorial/lesson6/
https://en.wikipedia.org/wiki/Threshold_model
https://stats.stackexchange.com/questions/239978/how-to-set-threshold-value
http://apstatsmonkey.com/StatsMonkey/AP_Review_files/StudentResources.pdf
https://shiny.rstudio.com/reference/shiny/latest/selectInput.html
https://michy-apps.shinyapps.io/control_charts/
https://github.com/mick001/control_charts_shiny/blob/master/control_chart_app.R
Comments
Post a Comment