R Shiny Server custom R location


I have installed R Shiny using the instructions here ->

It is on CentOS7.

We have a custom R location using enviroment modules.

The Webserver comes up but nothing runs as it can find R in the standard locations.

I have tried altering the service file /etc/systemd/system/shiny-server.service as such ->

ExecStartPre=/usr/bin/bash -c 'source /etc/profile.d/modules.sh; source /etc/profile.d/z_hpc.sh; module load R/3.4.3; which R >> /var/log/shiny-server.log'


ExecStart=/usr/bin/bash -c 'source /etc/profile.d/modules.sh; source /etc/profile.d/z_hpc.sh; module load R/3.4.3; which R;/opt/shiny-server/bin/shiny-server --pidfile=/var/run/shiny-server.pid >> /var/log/shiny-server.log 2>&1'

And although the environment can see R before starting the server can still not see R.

Can I somehow direct R shiny to a non standard R install or do I need install from source ?

Thanks Roger

What is the error report from shiny server process when it starts?
Can you confirm the user which is used to run R process (shiny by default) can run R from the custom location?

Hi Peter, root is running I can change this.

I have partly fixed the problem by doing a softlink from /usr/bin/R to the custom R. But often things still fail as a list of libraries need to be loaded too.


I've also tried setting up the Environment on the command line and running
/opt/shiny-server/bin/shiny-server --pidfile=/var/run/shiny-server.pid >> /var/log/shiny-server.log 2>&1

directly from the command line.

The error in the log is
Warning: Error in .rasterObjectFromFile: Cannot create RasterLayer object from this file; perhaps you need to install rgdal first
Stack trace (innermost first):

because R shiny has not got the Right environment.


Im getting this in some of the logs which could be the issue

su: ignore --preserve-environment, it's mutually exclusive to --login.

I have created a temporary fix for this by creating this file,

[root@ukvmlx-rshiny-01 log]# cat /usr/bin/R
module load R/3.4.3
R $*

It would be good to know the correct solution.


I do not know if you have solved this by now. I had the same problem, i.e. trying to run a shiny app on a shiny server with R and R libraries in non-standard locations, loaded by environment modules.
My solution is to run the shiny server as user shiny, and load the modules in the .profile file of user shiny (not the .bashrc, because user shiny uses the bourne shell).
Hope this helps,

I also used the workaround from scu98rkr.

Recently, RStudio Server supports loading env modules before startup. But only for the pro version.

Maybe there is better support coming in the future.

This finding really saved my weekend. Also tried the .profile workaround but that did not work for me.