1

I am writing an application in Shiny in R. Global.R is described as below to connect to PostgresSQL.

library(shiny)
library(DBI)
library(RPostgres)
library(RPostgreSQL)
library(pool)

pool <- dbPool(
  drv = RPostgreSQL::PostgreSQL(max.con=10000),
  dbname = "postgres",
  host = "shiny.com...",
  user = "postgres",
  password = "passward",
  idleTimeout = 3600000
)

I can connect without problems, but I am reluctant to write the password directly in global.R. Is there a good way to hide the password or write it somewhere else to read it? Thank you

Tim Ikata
  • 201
  • 1
  • 7

2 Answers2

0

There are several ways to do so. I assume you want an "automated" solution (i.e. no key to provide each time app is launched) therefore you may want to have a look to this SO post: Hide Keys in Shiny Application Deploy It basically involves an hidden file storing credentials.

yeahman269
  • 705
  • 7
  • 16
0

I recommend storing your password to .Renviron. You can easily access .Renviron using usethis::edit_r_environ(). Store it as, for example, YOURPASS = 'Password', and call it like this in your code:

pool <- dbPool(
  drv = RPostgreSQL::PostgreSQL(max.con=10000),
  dbname = "postgres",
  host = "shiny.com...",
  user = "postgres",
  password = Sys.getenv('YOURPASS')),
  idleTimeout = 3600000
)
ViviG
  • 1,613
  • 1
  • 9
  • 23