shinyapps doesn't allow you to specify dashboard-specific environment variables from the web interface. Instead, users must define a .Renviron file locally and ensure this is deployed with the app so that you can invoke Sys.getenv()
within your Shiny app to call on these vars.
This is problematic for a number of reasons with regards to development and production environments because developers must remember to switch between devel/prod settings when testing code between local and deployed.
I was wondering what current 'best practice' is with regards to handling env vars between devel/prod (in this case, prod is a shinyapps deployment). Is there some sort of env var switching that can occur in-script so that people don't have to remember to switch up variables?
For example (pseudo code):
if (working_locally = TRUE) {
pool <- dbPool(odbc::odbc(),
Driver = Sys.getenv('DEVEL_DB_DRIVER'),
Server = Sys.getenv('DEVEL_DB_SERVER'),
UID = Sys.getenv('WH_USER'),
PWD = Sys.getenv('WH_PW'),
Warehouse = Sys.getenv('DEVEL_WH'),
Database = Sys.getenv('DEVEL_DB'))
}
else {
pool <- dbPool(odbc::odbc(),
Driver = Sys.getenv('PROD_DB_DRIVER'),
Server = Sys.getenv('PROD_DB_SERVER'),
UID = Sys.getenv('WH_USER'),
PWD = Sys.getenv('WH_PW'),
Warehouse = Sys.getenv('PROD_WH'),
Database = Sys.getenv('PROD_DB'))
}