Search code examples
rshinyhandsontablerhandsontable

Shiny disabling the actionbutton for x seconds while exporting data to SQL DB


I have a handsontable with dynamic data and I am uploading it to the MSSQL DB with the sqlSave code with the Submit button in shiny.

However, I could bot find any function that will going to disable the actionbutton for lets say 10 seconds. I tried shinyjs::disable and withProgress, incProgress things but none of them worked.

Thank you,

dbhandle <- odbcDriverConnect('driver={SQL Server};server=....;database=...;trusted_connection=true')

 withProgress( 
 sqlSave(dbhandle, dat = some data), 
      tablename = "Budget_Tool", 
      rownames = F, append = T, verbose = T, fast = F, colnames = F, safer = 
      T), value = 1, 
      style = "notification", message = "Submitting, please wait..")

    --------------------
       actionButton("submit", "Submit", class = "btn-primary",
                    style="color: #fff; background-color: #337ab7; border-
      color: #2e6da4; font-size: 20px;"),

Solution

  • I fixed it by using hide and show;

     observeEvent(input$submit, {
      hide('submit', animType = "fade", time = 5)
    asd <- as.data.frame(cbind(Department = rv$data[,2], Cost_Summary_Key = 
      rv$data[,1], Calculated_Budget = rowSums(rv$data[,3:14]))) %>% 
      left_join(CSK_Budget, c("Department", "Cost_Summary_Key"))
    
       asd <- asd %>% mutate(Deviation = (as.numeric(Budget_2017) - rowSums(rv$data[,3:14])))
    
       x <- c()
    
       for (i in 1:nrow(asd)) {
    
      if(asd[i,5] >= -0.05)
      {x[i] <- TRUE} else {x[i] <- FALSE}
    
    }
    
    moment <- substr(Sys.time(), 1, 10)
    moment2 <- substr(Sys.time(), 12, 19)
    personel <- input$userName
    
    
    if( all(x))
    {
    
    
      dbhandle <- odbcDriverConnect('driver={SQL Server};server=...;database=...._SQL;trusted_connection=true')
    
      withProgress( 
        sqlSave(dbhandle, dat = (cbind(melt(rv$data, na.rm = F, varnames = c(Department, Cost_Summary_Key), as.is = F), Year = "2017", 
                                       Time_Stamp1 = moment, Time_Stamp2 = moment2, User = personel)), 
                tablename = ".....", 
                rownames = F, append = T, verbose = T, fast = F, colnames = F, safer = T), value = 1, 
        style = "notification", message = "Submitting, please wait..")
    
    
      js_string <- 'alert("Succes!!");'
      session$sendCustomMessage(type='jsCode', list(value = js_string))
      showNotification("Thanks, your response was submitted successfully!", duration = 5, type = "warning")
    }
    else {showNotification("Check Your Budget Items !!", duration = 3, type = "warning")}
    
    odbcCloseAll()   
    show('submit', animType = "slide", time = 1)
      })