I'm trying to build a Shiny application which will be connected to an unstable PostgreSQL Database with DBI. It works fine when the database is stable, but gives Whitelabel Error whenever the database is slow or down for a moment. How can I configure my application so that it will keep trying to connect a number of times before throwing error? A sample code is given below:
library(shiny)
library(DBI)
con <- dbConnect(
RPostgres::Postgres(),
host = "myip",
port = "myport",
dbname = "mydb",
user = "user",
password = "password"
)
ui <- fluidPage(
tableOutput("mytable")
)
server <- function(input, output, session){
output$mytable <- renderTable(
dbGetQuery(
con,
"select * from mytable;"
)
)
}
shinyApp(ui, server)