Reputation: 3292
I have a Shiny app that works as expected both locally and when containerized. The app receives some user input, queries a database, and returns a .zip
containing a .pdf
and .xlsx
file. Because reasons, I will be deploying it to a server running Shiny Server. When running the app, I get an error that processing the [filename].knit.md
is impossible because "Permission denied:"
After digging into why this might be the case, I think it's a function of the user shiny
(running the app in shiny-server.conf
) doesn't have permissions to access the dir/file. The trouble I'm having is diagnosing this error because the temp dir and file don't appear to exist anywhere in the local directory structure.
In server.R
, I call tempfile()
and use that temporary file as the input for output_file
in the render()
command. I know that tempfile()
is a subdirectory of the per-session temporary directory so how can I ensure that user shiny
can access any tempdir()
created during app operation?
Further, am I assuming correctly that the temp dir in the image above is automatically deleted when the app errors out? I can't find that dir anywhere in the /tmp
tree of the server.
Upvotes: 2
Views: 1448
Reputation: 1179
In the doc of tempdir()
By default, tmpdir will be the directory given by tempdir(). This will be a subdirectory of the per-session temporary directory found by the following rule when the R session is started. The environment variables TMPDIR, TMP and TEMP are checked in turn and the first found which points to a writable directory is used: if none succeeds ‘/tmp’ is used. The path should not contain spaces. Note that setting any of these environment variables in the R session has no effect on tempdir(): the per-session temporary directory is created before the interpreter is started.
So
mkdir mydir
export TMPDIR=mydir
Rscript -e "tempfile();tempdir();"
give
[1] "mydir/RtmphR2Rkx/file19da392dac5546"
[1] "mydir/RtmphR2Rkx"
Else give the right to /tmp
Upvotes: 2