I'm learning how to use shinyproxy to deploy R shiny applications but I can't figure out where to place my .Renviron
file which contains global variables used to access a database.
The docker image builds without any errors but when I start the container using:
docker run -it -p 3838:3838 shinyproxy-template .
It doesn't find the env variables in the .Renviron
file and I end up getting an error on the part of the R code that requires the global variables.
My current folder structure is as follows:
shinyproxy-template/
|- app-folder/
|- .gitignore
|- Dockerfile
|- README.md
|- app.Rproj
|- Rprofile.site
|- .Renviron
I tried placing the .Renviron
file inside the app-folder/
then built the docker image again but the global variables were still inaccessible.
Where should I place the .Renviron
so that the global variables are accessed by the app?
There are multiple options:
.Renviron
file to the expected location inside the containerYou can add a COPY
command to the Dockerfile
to copy your .Renviron
file to the expected location - i.e. either a home directory of the user or the WORKDIR
location if defined in the Dockerfile. In case of the root user it would be:
COPY .Renviron /root/
.Renviron
to the DockerfileAdd lines like:
ENV VAR1="value1"
ENV VAR2="value2"
to your Dockerfile
.Renviron
to the shinyproxy configurationYou can define environment variables in the application.yaml
configuration file by either using
container-env:
VAR1: VALUE1
VAR2: VALUE2
or
container-env-file: /path/to/.Renviron
for your app specification. Note that the path here is on the host and not inside the container.
docker run
When you do a docker run
outside of shinyproxy you can use argument --env-file
with something like:
docker run -it -p 3838:3838 shinyproxy-template --env-file /path/to/shinyproxy-template/.Renviron
Releant documentation links: