How to run R Shiny on



To run R Shiny on


You will need:

Problems offers many different language runtimes by default, but some applications require different environments, such as data science applications which use R Shiny. By installing the Miniconda Python package manager, it is possible to run R applications, such as R Shiny, on


1. Set git remote to project

$ git init
$ platform project:set-remote <project id>

2. Create an installation script file

The build hook runs Dash, not Bash, so the installation script is executed separately in


# Download the latest Miniconda3 release and name the file ``
curl -o

# Run the downloaded `` script using bash
# — Use the `-b` flag to run the installer in batch mode
# — Use the `-p` flag to specify where the package manager will actually be installed
bash -b -p $PLATFORM_APP_DIR/conda

# Source the following `` file to put the `conda` command in our path for the duration of this script
. /app/conda/etc/profile.d/

# Add the above command to `.bash_profile` so that it is available during SSH sessions
echo ". /app/conda/etc/profile.d/" >> ~/.bash_profile
echo "conda activate" >> ~/.bash_profile

# Enter the base conda environment and make sure it is up to date
conda activate base
conda update -n base -c defaults conda

# Install R
# `r-essentials` is a bundle of 80 common R packages, including `r-shiny`.
# Remove `r-essentials` from the line below to only have a barebones install.
# The `-n` flag gives the environment its name.
conda create -n r-env r-essentials r-base

# Activate the freshly created environment
conda activate r-env

# Install additional packages if desired
# conda install r-rbokeh

IMPORTANT: When using conda to install R packages, you will need to add r- before the regular CRAN or MRAN name. For instance, if you want to install rbokeh, you will need to use conda install r-rbokeh.

3. Add a start script for running scripts with R


# Source the `` file to make this particular shell session able to run the `conda` command
. /app/conda/etc/profile.d/

# Activate the conda environment that was created in the build hook
conda activate r-env

# Run the Shiny web app
Rscript start_shinyapp.R

4. Add a Shiny app in the shinyapp directory

In the file shinyapp/app.R:


# Define UI for application that draws a histogram
ui <- fluidPage(

   # Application title
   titlePanel("Old Faithful Geyser Data"),

   # Sidebar with a slider input for number of bins
                     "Number of bins:",
                     min = 1,
                     max = 50,
                     value = 30)

      # Show a plot of the generated distribution

# Define server logic required to draw a histogram
server <- function(input, output) {

   output$distPlot <- renderPlot({
      # generate bins based on input$bins from ui.R
      x    <- faithful[, 2]
      bins <- seq(min(x), max(x), length.out = input$bins + 1)

      # draw the histogram with the specified number of bins
      hist(x, breaks = bins, col = 'darkgray', border = 'white')

# Run the application
shinyApp(ui = ui, server = server)

5. Add a script for running the R app

Create the R script start_shinyapp.R:

options( = "")
options(shiny.port = 8888)

6. Add

Create the configuration file:

# The name of this app. Must be unique within a project.
name: app

# The runtime the application uses.
type: "python:3.7"

# The hooks executed at various points in the lifecycle of the application.
    build: |
      set -e

      # The build hook uses `dash` rather than `bash`.
      # Thus, the installation occurs in separate script that runs with `bash`.

    deploy: |
      set -e

      # Make the start script executable
      chmod +x

# The size of the persistent disk of the application (in MB).
disk: 1024

# The configuration of app when it is exposed to the web.
        start: bash ./
        socket_family: tcp
        protocol: http
            passthru: true
        PORT: 8888

7. Define routes


  type: redirect
  to: "https://{default}/"

  type: upstream
  upstream: "app:http"
  primary: true
  id: http
      enabled: false

8. Add empty services


# empty

9. Add, commit, and push these files to your project

git add .
git commit -m "Adding configuration to install R Shiny"
git push platform master

10. Visit the URL on the app that was just created

platform url


By executing the Anaconda or Miniconda installation Bash scripts in the build hook, a project is able to install an Conda-based execution environment on