How to sync ShinyApps with MySQL From Localhost to Public

Multi tool use
Multi tool use


How to sync ShinyApps with MySQL From Localhost to Public



I am currently developing an app using R Shiny and finishing my ShinyApps, now I am trying to deploy the apps to Shinyapps.io so multiple user can reach and use it, but I have an issue for the deployment.



my Apps is about a Pharmacy management, it controls a CRUD operation, so clearly it is binded with db Connection using these options configuration (running this in locally)


options(mysql = list(
"host" = "127.0.0.1",
"port" = 3306,
"user" = "root",
"password" = ""
))



one more thing, to connect to database, I usually started my XAMPP apps and switched on mysql admin so my apps can connect the database locally. it worked flawlessly and clear before deploy



but it crashed instantly when I try to run it in the shiny.io after delpoy (what I mean is disconnected automatically). so I did try to change the host ip to publically like this , (I am trying to get ip address on user local machine)


configA <- system("ipconfig", intern=TRUE)
configB <- configA[grep("IPv4", configA)]
configC <- gsub(".*? ([[:digit:]])", "1", configB)

options(mysql = list(
"host" = configC,
"port" = 3306,
"user" = "root",
"password" = ""
))



the ConfigC variable stores IPv4 address to get the public IP on local machine, but still these doesn't work, I attached a log in below link



how can I connect and sync my apps with MySQL in Shinyapps.io ? I use DBI and RMySQL package..do I need to host MySQL first so i can sync my apps? can anyone brief me with step by step explanation how to? thankyou in advance



here is my error log from shinyapps.io
http://textuploader.com/dulzh




1 Answer
1



For people who have same problem & didn't know how, i'll share what have work for me:



1) I Recommend Host your MySQL Database to AWS (Amazon Web Service), it is free and great performance to sync any Web Service update online especially shinyapps.io, with creating an Account first



2) Validate your AWS Account with full information including credit card, so you can access its Services



3) Click Service > Database > RDS



4) Then you will be redirected to AWS RDS Dasboard, here you can manage Instances of your MySQL Database, to create one new Instance, click Launch DB Instance



5) Here is my Instance settings:
Engine Options: MySQL



Use Case: Production- MySQL



DB Instance Class: db.r4.large 2vCPU, 15.25 GiB RAM (i believe this setting is subjectively based on our CPU performance)



Multi AZ Deployment: No



Storage Type: Provisioned IOPS



Allocated Storage: 100 GiB



Provisioned IOPS: Depends on your Allocated Storage (I use 4000)



6) Then in Settings tab, fill your db instance identifier, master username & password, after that when you click Next, there is advanced configuration, fill again db name and then you will want to check all Log Reports in hope an easier maintenance later, after finished > Launch DB Instance



7) Wait until your instances status become Available (keep refreshing to know)



8) After the Instance become Available, check the Instances and scroll down until you found Connect section, remember and save the Endpoint, Security Group Rules, master username & password Instances from Detail section



9) In your server.R, edit your MySQL connection options, from localhost to AWS RDS..


options(mysql = list(
"host" = "your Endpoint",
"port" = 3306,
"user" = "your master username of db instance",
"password" = "your master password of db instance"
))



10) Before deploying your MySQL database from localhost to AWS RDS, firstly Go to your AWS > Services > VPC > Security Group > (Click one of Group Name that is actively used by your Instances)> Inbound Rules



11) In Inbound Rules you must whitelist all External IP that you or other PC access to your shinyapps http://whatsmyip.org, and whitelist all shinyapps IP address based on this http://docs.rstudio.com/shinyapps.io/applications.html#accessing-databases-with-odbc in section 3.8.4



12) And now lastly, to deploy your MySQL Database from localhost to AWS RDS cannot be done directly, I Recommend installing MySQL Workbench to do it, after done installing, launch MySQL WorkBench



13) Create new MySQL Connection adn then fill the connection form:
Connection Name: (anything you like)
Connection method: TCP/IP
Hostname : (paste your Endpoint)
Port 3306
Username: (your master username of db instance)
Password: (your master password of db instance)



14) After a successful Connection to AWS RDS, open your connection, and then MySQL WorkBench UI will open, Import your .bak files (MySQL database) from Navigator > Management > Data Import > Select Import from Self Contained Files > browse your file> and then start Import



15) You have successfully deployed your database to AWS RDS! you can use query in WorkBench to see all your table/database information



16) RunApp your ShinyApps and test it, and DONE!



(if you EVER found message can't connect to your AWS RDS host, probably that your External IP is changed to new one, and to solve it you need to whitelist again your IP to AWS VPC in step 10)



I hope these are helpful for you!






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

rHGgU0ZdLhv 1RNBBPIYql5krbzOl0C h1Ve,dUQAS TGYgP I1,f0kbTQQ1DFw4dTFMJj,5 I
wMHTCzzk4Orh6zTf4 zfnDDwHKxl CcMDOISLQHPUcVx

Popular posts from this blog

Rothschild family

Cinema of Italy