-
Notifications
You must be signed in to change notification settings - Fork 185
Description
tbl() does appear to make a connection with the database, and I am hoping there is a solution to make it lazy to improve loading speeds of a shiny app.
For context, I have a shiny app that builds several base queries in a global list in global.R to avoid repeating work across multiple users. As the app is hosted on shinyapps.io (which I believe is hosted in NA) and my database is in Australia, there's some lag I can assume is attributed to internet speed (It is much faster locally run). On shinyapps.io it can take 23-45 seconds to call all the tbl() objects which is a huge chunk of time in the initial loading time.
I've tried adding vars = null which I got from this page as I can only assume the delay is caused by retrieving the column names, but this does not appear to help as the column names still appear in the object list.
Is there any way to avoid the initial fetching of column names?
#' Get module queries as list
#'
#' @param pool connection object
#' @param module_name name of module as specified in `golem-config.yml` file
#'
#' @return list of queries filtered to module
utils_queries__get_all_queries <- function(pool) {
queries <- list()
tables <- get_golem_config("tables")
schema <- get_golem_config(
"schema",
config = Sys.getenv("GOLEM_CONFIG_ACTIVE")
)
for (table in names(tables)) {
resolved_table_name <- glue("{schema}.{tables[[table]]$table_name}")
queries[[table]] <- tbl(pool, I(resolved_table_name), vars = NULL)
}
return(queries)
}