0

Below is the part of my server code. Actually there is an error in SQL for some conditions. So when I execute in R calling SQL, the R shiny crashes. So i tried putting trycatch(). Even then the app crashes but I can see notifications when app crashes. Please anyone help

if(input$ID != "" && !is.null(input$Date)){

      # to get data from SQL
      tryCatch({
      # to get data from SQL
      sql <- paste0("SELECT * FROM [SSS].[AAA].[CCC]")
      df1 <- sqlQuery(db, sql)   # db is already declared
        },

      error = function(err){
        showNotification(paste0(err), type = 'err')
      })
imran p
  • 332
  • 2
  • 12

1 Answers1

0

You could try to do df1 <- sqlQuery(db, sql, errors=FALSE), which should return -1; you could then check df1 != -1 before continuing in your code.

edit: You could do something like:

myReactiveFun <- reactive({
  shiny::req(input$Date)
  sql <- paste0("SELECT * FROM [SSS].[AAA].[CCC]")
  df1 <- sqlQuery(db, sql, errors=FALSE) 
  shiny::validate(shiny::need( df1 != -1, "need valid SQL query result...")

})
user12728748
  • 8,106
  • 2
  • 9
  • 14