# Function to get user for database
pg_user <- function(user_label) {
Sys.getenv(user_label)
}
# Function to get pw for database
pg_pw <- function(pwd_label) {
Sys.getenv(pwd_label)
}
# Function to get pw for database
pg_host <- function(host_label) {
Sys.getenv(host_label)
}
# Define globals ================================================================
# Pooled connection to sport_sampling DB
pool = pool::dbPool(drv = RPostgres::Postgres(),
host = "localhost",
dbname = "sport_sampling",
user = pg_user("pg_user"),
password = pg_pw("pg_pwd_local"),
port = '5432')
# Avoid importing remisc package
get_uuid = function(n = 1L) {
if (!typeof(n) %in% c("double", "integer") ) {
stop("n must be an integer or double")
}
uuid::UUIDgenerate(use.time = FALSE, n = n)
}
# Function to close pool
onStop(function() {
pool::poolClose(pool)
})
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.