Help passing form.yml variable to script.sh.erb for Interactive Application

Hello

We have an RStudio interactive app which has been working well. We are trying to add an enhancement so the user can select which version of R to load with RStudio. I added the following to form.yml:

  r_version:
    widget: "select"
    options:
      - ["default","default"]
      - ["4.2.0","4.2.0"]
      - ["4.1.3","4.1.3"]
      - ["4.1.2","4.1.2"]
      - ["4.1.1","4.1.1"]
      - ["4.1.0","4.1.0"]
      - ["4.0.5","4.0.5"]
      - ["4.0.4","4.0.4"]
      - ["4.0.3","4.0.3"]
      - ["4.0.2","4.0.2"]
      - ["4.0.0","4.0.0"]
      - ["3.6.3","3.6.3"]
      - ["3.6.0","3.6.0"]
      - ["3.5.3","3.5.3"]
      - ["3.5.0","3.5.0"]
      - ["3.3.0","3.3.0"]
      - ["3.2.0","3.2.0"]
      - ["3.1.0","3.1.0"]
      - ["3.0.0","3.0.0"]
      - ["2.15.0","2.15.0"]

and also added r_version to the form: section

form:
  - r_version
  - bc_queue
  - bc_num_hours
  - slurm_mem
  - slurm_cores
  - slurm_scratch

Now, I would like to use the value of r_version in script.sh.erb but I am struggling to understand how the variable scoping works with erb. I naively tried:

#!/usr/bin/env bash

r_version="<%= r_version %>"

if [[ ${r_version} == "default" ]]; then
    r_version=""
fi

module load CBI
module load r/"${r_version}"
module load rstudio-server-controller

# Start RSC launching the personal Rstudio Server instance
rsc start --port="${port:?}"

This results in:

Failed to stage the template with the following error:

undefined local variable or method `r_version' for #<BatchConnect::Session::TemplateBinding:0x00007f248535da80>

    The RStudio Server session data for this session can be accessed under the staged root directory.

Any help would be greatly appreciated.

-Harry

You need to use context.r_version.

Works perfectly, thanks so much!