Action Button


   It was rough trying to debug the app. I am trying to add an action button so that the graph can update based on what variables the client chooses. After a while, I had to restart to where I left off last time, so that I could move forward with ease.

   My goal today is to get the action button to update the control chart. It is not working the way I want it to. The chart is still not updating.




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



mydata <-read.csv("dummydata.csv")
variables <- 1:ncol(mydata)
names(variables) <- names(mydata)


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")
      ), #fileInput
     
     
      selectInput(inputId = "var", label = "Choose which variable you want to graph", choices = variables), #selectInput
     
      actionButton(inputId = "button", label = "Go") #actionButton
    ), #sidebar panel
   
   
   
    mainPanel(
     
      plotOutput(outputId = "controlchart"),
      dataTableOutput(outputId = "datachart")
     
    ) #main panel
  ) #sidebar layout
) #user interface






server <- function(input, output, session) {
 
 
 
 
  loadedFile <- reactive({
    file <- input$file1
    file
  }) #loadedFile()
 
 
 
 
  observeEvent(
    input$button,

 
 
  output$controlchart <- renderPlot({
    file <-loadedFile()
   
    if(is.null(file))
    {
      d <-mydata
    }
    else
    {
      d <-read.csv(file$datapath)
    }
   
    mr = 0
    mean = 0
    UCL <-  mean + 2.66*mr
    LCL <- mean - 2.66*mr
   
   
   
    spcChart <- qcc(d, type = "xbar", title = "Xbar Chart") #qcc
   
    (warn.limits <- limits.xbar(spcChart$center, spcChart$std.dev, spcChart$sizes, 2))
    plot(spcChart, restore.par =  FALSE)
   
   
   
  }) #render plot
 
  )#observeEvent
 
  output$datachart <- DT::renderDataTable({
   
    file <-loadedFile()
   
    if(is.null(file))
    {
      d <-mydata
    }
    else
    {
      d <-read.csv(file$datapath)
    }
    d
  }) #render data table
 
 
 
 
 
} #server function

shinyApp(ui = ui, server = server)







Sources Used:

https://stackoverflow.com/questions/25871292/r-need-finite-ylim-values-in-function

https://shiny.rstudio.com/gallery/actionbutton-demo.html

https://stackoverflow.com/questions/32260143/refresh-input-values-in-shiny-app-with-actionbutton

http://shiny.rstudio.com/articles/action-buttons.html

https://stackoverflow.com/questions/38852916/shiny-selecting-specific-columns-from-uploaded-data-frame

https://flowingdata.com/2012/12/17/getting-started-with-charts-in-r/

Comments