My application works localy. When I deploy it on shinyapps.io it seems to work but sometimes I get an error:
It can't connect to the database, too many connections. Then if I try in a few minutes it works. Then I try again and it doesn't work. My code looks like this
library(shiny)
library(shinydashboard)
library(formattable)
library(dplyr)
library(DBI)
library(pool)
pool <- dbPool(
drv = RMySQL::MySQL(),
dbname = "my_db_name",
host = "my_db_host",
username = "my_username",
password = "my_password",
port = 3306
)
onStop(function() {
poolClose(pool)
})
ui <- dashboardPage(
# Code here
)
server <- function(input, output) {
data_all = pool %>%
tbl('table_name') %>%
as.data.frame()
# Code here
}
# Run the application
shinyApp(ui = ui, server = server)
As I understand, when I deploy an app pool object is created. When new users opens an app it gives him a connection (creates new if required). My app is used only by me so I don't understand this error. Can someone help me explain why is this happening and how to fix it?