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?
2
Answers
Edit: Have a look at @Max's solution. We posted at nearly the same time but his instructions are clearer.
After lots of trial and error I finally got a solution.
First, starting the container outside shinyproxy to check if the shiny app runs normally? Use docker's
--env-file
flag to specify the.Renviron
filepath. In my case since both theDockerfile
and.Renviron
are in the same folder so I'd do:The app will now recognize env vars defined in the
.Renviron
file and no errors!I then changed into the directory where I had
shinyproxy-2.6.1.jar
file and ran it again usingjava -jar shinyproxy-2.6.1.jar
. There was an error when I tried to start my shinyapp. It couldn't find the env vars.So I resorted to adding them directly in the
application.yml
which is in the same location asshinyproxy-2.6.1.jar
:Replace the necessary parts of the yml section with the corresponding one's on your side depending on your case. The same applies to the env vars.
In fact let me just provide a prototype of my whole
application.yml
file, have a look at the last app I added "wca":There's obviously a better solution to refer to the
.Renviron
file directly but since I can't figure it out this will do.There are multiple options:
Put
.Renviron
file to the expected location inside the containerYou can add a
COPY
command to theDockefile
to copy your.Renviron
file to the expected location – i.e. either a home directory of the user or theWORKDIR
location if defined in the Dockerfile. In case of the root user it would be:Add environment variables from
.Renviron
to the DockerfileAdd lines like:
to your
Dockerfile
Add environment variables from
.Renviron
to the shinyproxy configurationYou can define environment variables in the
application.yaml
configuration file by either usingor
for your app specification. Note that the path here is on the host and not inside the container.
For
docker run
When you do a
docker run
outside of shinyproxy you can use argument--env-file
with something like:Releant documentation links: