vhio
vhio

Reputation: 167

R Shiny can't connect to MySQL database hosted on GCP

I can access the database if I run the app from my local machine without problems, but after deployment on shinyapps.io, I get an error ("The application failed to start."). I suppose that I need to change to host IP from localhost to something else, but the IP address of my database instance does not work either.

pool<- dbPool(
  drv = RMySQL::MySQL(),
  dbname = 'XXXXXX', 
  username = 'XXXXXX',
  password = 'XXXXXX',
  host = '127.0.0.1',
  port = 3307
)

For the local connection, I use Cloud SQL Proxy.

  1. Any ideas how the app could connect to the database from the Shiny Server?
  2. How can I account for both the local machine's connection and the cloud-to-cloud connection in my code?

This question is similar but without Cloud hosting: Error to connect to database (Mysql) when publising shiny app

Upvotes: 1

Views: 304

Answers (1)

Darwin
Darwin

Reputation: 480

To connect to your Cloud SQL instance using public ip, the IP address of your Shiny server where your app is deployed must configured as an authorized network

You may check this link on how to configure authorized networks and connect your Cloud SQL instance using public ip address.

Note: If you're going to deploy your application, you may need to modify the host IP and use your sql instance public ip address in your code.

Upvotes: 1

Related Questions