-
Notifications
You must be signed in to change notification settings - Fork 137
Description
Hey @ColinFay and golem team,
I have a question I hope is pretty straightforward. Even after reading this, I'm still a bit confused on options as they pertain to golem shiny applications.
Basically, I have two databases, Development and Production. When I am testing/developing an app locally, I'd like to use the Development credentials, and similarly when the app is hosted on RSConnect, I'd like to use the Production credentials.
For Development, I store credentials in a .Renivron file, for Production I store credentials in RSConnect environment variables. In both cases, I use the !expr Sys.getenv("[option_name]") syntax in golem_config.yml to get the value.
I am curious as to how I would go about allowing my app to be run in both DEV and PROD modes, locally. Basically, allow me to "turn a switch" so that I can connect to Production to see what the app looks like before I actually deploy it to RSConnect. In my golem_utils_server.R file, I have the following:
if(golem::app_dev()){
message("Connected to Development DB")
#Dev pool connection
pool <- pool::dbPool(
RPostgres::Postgres(),
dbname = get_golem_config("dev_db_name"),
host = get_golem_config("dev_db_host"),
port = get_golem_config("dev_db_port"),
user = get_golem_config("dev_db_username"),
password = get_golem_config("dev_db_password")
)
} else if(golem::app_prod()){
message("Connected to Production DB")
#Prod pool connection
pool <- pool::dbPool(
RPostgres::Postgres(),
dbname = get_golem_config("prod_db_name"),
host = get_golem_config("prod_db_host"),
port = get_golem_config("prod_db_port"),
user = get_golem_config("prod_db_username"),
password = get_golem_config("prod_db_password")
)
}
onStop(function() {
pool::poolClose(pool)
})
and the golem_config.yml looks like
default:
golem_name: GeneDataEditoR
golem_version: '0.1'
app_prod: no
dev_db_username: !expr Sys.getenv("db_username")
dev_db_password: !expr Sys.getenv("db_pw")
dev_db_port: !expr Sys.getenv("db_port")
dev_db_host: !expr Sys.getenv("db_host")
dev_db_name: !expr Sys.getenv("db_name")
production:
app_prod: yes
dev:
golem_wd: /home/kweise/GeneDataEditoR
rsconnect:
prod_db_username: !expr Sys.getenv("db_username")
prod_db_password: !expr Sys.getenv("db_pw")
prod_db_port: !expr Sys.getenv("db_port")
prod_db_host: !expr Sys.getenv("db_host")
prod_db_name: !expr Sys.getenv("db_name")
I tried setting: options(golem.app.prod = T), but I'm still seeing "Connected to Development DB" when I run the app. How can I make golem::app_prod() return TRUE?
Thanks so much! And again, amazing package!
-Kyle