Home

Awesome

Heroku R Docker Image

Build & Publish

This is the docker image for applications which use R for statistical computing and CRAN for R packages, running on Heroku.

This project is compatible with the heroku-buildpack-r so that it is possible to migrate your existing Heroku R applications and deploy them using the new Heroku container stack, however there are some caveats if multiple buildpacks were used together with heroku-buildpack-r.

The new stack alleviates many of the complexities and issues with the R buildpack.

Pre-built docker images are published on GitHub Container Registry, and are based off the official Ubuntu docker images. Previous versions were published to Docker Hub.

Support has been added for packrat and renv package managers.

NOTE: Docker is not required to be installed on your machine, unless you need to build and run the images locally. For the most common use cases, you can probably use the default configuration so it won't be necessary to have docker installed.

Usage

Shiny Applications

These steps are for Shiny applications.

In your Shiny application source's root directory:

See heroku-docker-r-shiny-app for an example application.

Plumber Applications

These steps are for Plumber applications.

In your Plumber application source's root directory:

See heroku-docker-r-plumber-app for an example application.

Other R Applications

These steps are for console and other types of R applications.

In your R application source's root directory:

Applications with Additional Dependencies

For R applications which have additional dependencies, the container stack gives you much more flexibility with the Dockerfile than was previously available in the R buildpack; such as for installing dependencies from other sources, from deb files or by compiling libraries from scratch, or using docker's multi-stage builds. It also provides greater control over the runtime directory layout and execution environment.

To make it easier for project authors to manage dependencies and provide backward compatibility with the heroku-buildpack-r without the need for Docker to be installed, the following functionality is provided:

In each of the following examples, Docker's ONBUILD method is used to execute the step when the respective file is detected.

Multi-Language Applications

For applications which use another language, such as Java, Python or Ruby to interface with R, the container stack gives you much more flexibility and control over the environment, however the onus is on the developer to configure the language stack within the docker container instead of with mulitple buildpacks.

In each example, the language runtime can be installed via the use of an onbuild Bash script, which must be in the root of the project directory, and which is invoked during the deployment process.

This shell script can run installations such as using apt-get for example, or any other commands to setup language support and perform configuration as needed.

There are of course many permutations possible, so some examples are provided to help you get the idea:

Existing R Applications

For R applications which use the heroku-buildpack-r, this project provides backward compatibility so that you can continue to enjoy the benefit of using Heroku to deploy and run your application, without much change.

The process continues to use your init.R file in order to install any packages your application requires. Furthermore, the Aptfile continues to be supported in order to install additional binary dependencies.

It is worth nothing that use of multiple buildpacks is not supported nor needed on the container stack, so you may have some rework to do if you made use of this feature.

Please see the MIGRATING guide for details on how to migrate your existing R application.

Speeding Up Deploys

Since the container stack makes use of docker together with a Dockerfile to define the image, it is possible to speed up deployments by pre-building them.

NOTE: This requires having docker installed and an account on Docker Hub or other Heroku accessible container registry.

An example of how this is done can be found in the "speedy" example application.

Versions

The following versions for ghcr.io/virtualstaticvoid/heroku-docker-r are available on GitHub Container Registry, including:

Ubuntu VersionR VersionBase TagBuild TagShiny TagPlumber Tag
22.044.2.2latestbuildshinyplumber
22.044.2.24.2.2-build4.2.2-shiny4.2.2-plumber
22.044.2.14.2.1-build4.2.1-shiny4.2.1-plumber

Previous versions for virtualstaticvoid/heroku-docker-r are available on Docker Hub, including:

Ubuntu VersionR VersionBuild TagShiny TagPlumber Tag
20.044.1.04.1.0-build4.1.0-shiny4.1.0-plumber
20.044.0.54.0.5-build4.0.5-shiny4.0.5-plumber
20.044.0.24.0.2-build4.0.2-shiny4.0.2-plumber
20.044.0.14.0.1-build4.0.1-shiny4.0.1-plumber
20.044.0.04.0.0-build4.0.0-shiny4.0.0-plumber
20.043.6.33.6.3-build3.6.3-shiny3.6.3-plumber
20.043.6.23.6.2-build3.6.2-shiny
20.043.5.23.5.2-build3.5.2-shiny
20.043.4.43.4.4-build3.4.4-shiny

Examples

The examples repository contains various R applications which can be used as templates.

They illustrate usage of the docker image and the configuration necessary to deploy to Heroku.

Credits

License

MIT License. Copyright (c) 2018 Chris Stefano. See MIT_LICENSE for details.

Additional Information

R is "GNU S", a freely available language and environment for statistical computing and graphics which provides a wide variety of statistical and graphical techniques: linear and nonlinear modelling, statistical tests, time series analysis, classification, clustering, etc. Please consult the R project homepage for further information.

CRAN is a network of FTP and Web Servers around the world that store identical, up-to-date, versions of code and documentation for R.