Thisara Watawana
Thisara Watawana

Reputation: 344

Access local mysql server with shiny.io

I'm trying to create shiny app in shiny.io which requires access to a MySQL database which is located in my local machine. Is it possible to use RMySQL to connect to the local database by shiny.io? And how can I do that?

Upvotes: 2

Views: 2091

Answers (3)

Rich Pauloo
Rich Pauloo

Reputation: 8392

Within your mySQL database, whitelist shinyapps.io IP addresses.

See this helpful post from Rstudio support.

Upvotes: 0

Juanan
Juanan

Reputation: 1420

I'm a little "late" with my answer, but keep in mind that if you are deploying to shiny.io then "localhost" is pointing to shiny.io and there is no mysql for you there :-) So you should have to open your MySQL server and use your public IP address in "host" variable. Not that I am proposing this, from the security point of view it is not wise to open your MySQL server to the public. If you follow this way, at least, you should filter connections to only allow the IP address of shiny.io.

Another solution -more reasonable, in my opinion- might be to use an already public server that offers you a persistence layer, such as mongohq.com (now compose.io). They use MongoDB (not MySQL) but it could satisfy your needs (and you will get a 512MB RAM testing server for free). You may want to study this working example that uses shiny.io and mongo in order to start your project up.

Upvotes: 3

Haleemur Ali
Haleemur Ali

Reputation: 28233

The usage is essentially the same as in regular R script. you can put this at the top of your server.R file

library(RMySQL)
con = dbConnect(MySQL(), user='myusername', password='mysillypassword', db='dataaa', host='localhost')

query = "SELECT 1"
result = dbGetQuery(con, query)

Now result will be available for the rest of the shiny app.

You can also build the query inside a reactive function, and dynamically query the database.

Upvotes: 0

Related Questions