Automating the Deployment and Scheduled Execution of an R script on a VPS using Laravel Forge

I love data, its in my blood, I love analysing, cleaning it and preparing it for others to use, still have to get to the last mile to displaying and visualizing it but that is a story for another day

2024 for me is the year of “automation”, for everything that I do. I have been polishing up my R skills over the holidays, as a way for moving into Python based data wrangling, however the challenges that I have faced is to do with getting my R scripts to run regularly – this has to be on a server connected to the internet since my laptop is not always on

I tried ShinyApps in the past, but this needed me to learn more things which I did not have bandwidth for.

So when Contabo my host wiped my dev VPS during the holidays, I had to re-build my sites, one of which was a documentation site built using PHP and markdown, which I wrote about Deploying a Tighten Jigsaw static site to a VPS using Laravel Forge I was deploying generated HTML to the VPS, then it hit me can’t I do the same with an R script

Setup and Configuration

  1. Install R on your server, here are steps to install R v4.x (I was able to get 4.3.2) https://medium.com/@hpgomide/how-to-update-your-r-3-x-to-the-r-4-x-in-your-linux-ubuntu-46e2209409c3
  2. Create a static site via Laravel Forge from the screenshot below
    • The domain does not really matter, use any custom sub-domain, even if it does not exist since we shall not be accessing this site anyway
    • Select Static HTML/Next.js/Nuxt.js
    • Select “website Isolation” where you specify a user name for the site, I tend to do this alot allowing me to do custom commands without using the global forge user
    • Create a new static site with Laravel Forge
  3. Install your site code repository, GitHub/Gitlab are natively supported, and uncheck the “Install Composer dependencies”, we do not need this for R
    • Install Repository
  4. The magic happens in the Deployments tab which is enabled once you have connected the code repository
    • Firstly “Enable Quick Deploy” so that whenever you push code to the selected branch in Step #2 above the code is deployed
    • Customize your R script to be executed, in my case it was a simple as in the image below. I would also recommend keeping it as simple as you can to reduce deployment headaches
    • R execution script
  5. You can also test a deployment by clicking the “Deploy Now” button at the top of the page which will re-run the last deployment

Laravel Forge is $12 per month for a single VPS, then costs $19 per month for unlimited servers

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.