password in odbc connection using the rstudioapi package in a shiny app

In my shiny application, in global.R I have defined an odbc connection as follow :

con <- dbConnect(odbc(),
                 DSN = 'abc',
                 Database = 'xxx',
                 UID = rstudioapi::askForPassword("username"),
                 PWD = rstudioapi::askForPassword("password")
)

The app is working when I try it from RStudio IDE, but it is not when I deploy the app to the shiny server. The error is :

Error: RStudio not running
Execution halted

But if I change the odbc connection to :

con <- dbConnect(odbc(),
                 DSN = 'abc',
                 Database = 'xxx',
                 UID = "myuser",
                 PWD ="mypass"
)

The app will work properly both in IDE and on shiny server. Any Idea how that could fix to avoid using the username / pass in the code ?

1 Like

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.