Running R scripts on Heroku in a Rails App

If you already have a Rails app running R scripts in development with the rinruby gem, follow these steps to host it on Heroku. If you'd like to read more on how to work with rinruby, take a look at this.

Steps to run R on Heroku in a Rails App:

1.) Add the multibuildpack configuration variable to your heroku app

You can add it through command the line with the following:
heroku config:add BUILDPACK_URL=

2. ) Add a file named .buildpacks to your project root and add then add the URLs for both R and Ruby. The # at the end of the URL references a branch. Make sure your app is running on the stack cedar 14. You can specify it when you create your app . . .
$ heroku create --stack cedar-14

The R buildpack is a third party buildpack, but the Ruby buildpack is from Heroku. Include both of them.

3.) Add a file named init.r and place it in the project root with the packages you want to have installed.

Example with 1 package:

install.packages("nlme", dependencies = TRUE)

Example with 3 packages:

install.packages(c("nlme", "knitr", "RMySQL"), dependencies = TRUE)

Potential Problem with Assets:

If your css and javascript files do not compile, update config/environments/production.rb

config.assets.compile = true

That should do it. It could take as much as 10 minutes or so to deploy since you are installing the buildpacks and R.

May. 26 2015