radhikesh93
radhikesh93

Reputation: 940

open source shiny server on an instance on gcp can't connect to cloud sql

I am trying to host a shiny app on the open source shiny server which is installed on a virtual machine on gcp. The app is trying to connect to a remote Postgresql database that's also on gcp's cloud sql.

Below is my code for database connection

library(RPostgreSQL)
drv <- dbDriver("PostgreSQL")
con <- dbConnect(drv, dbname="test",
                 host="**.**.**.**",
                 user="username",
                 password="pwd", port=5432)

I had white listed the public ip address of my gcp's instance on cloud sql. But still my app doesn't run. The app runs fine on R studio server(which is also installed on the same instance). Can someone please help or provide any suggestions.

Thanks

Upvotes: 2

Views: 259

Answers (1)

radhikesh93
radhikesh93

Reputation: 940

My app work's now. It seems I made a naive mistake.

For future users, below is what I did wrong and how I corrected it.

While creating the app on R studio server, I installed all my packages from R studio server. And I didn't thought that these packages are not installed at the root, they were installed at the user level and shiny-server can't access these. I installed all the required packages again at the root

sudo su - -c "R -e \"install.packages('packagename', repos='https://cran.rstudio.com/')\""

and then my shiny-app works.

Upvotes: 2

Related Questions