R programming language

  • Click here for my notes on Shiny


If you get The application failed to start followed by:

The application exited during initialization.
  1. Edit /etc/shiny-server/shiny-server.conf and add sanitize_errors off;:

    run_as shiny;
    server {
      listen 3838;
      # Define a location at the base URL
      location / {
        sanitize_errors off;
        # Host the directory of Shiny Apps stored in this directory
        site_dir /srv/shiny-server;

    When you refresh the browser, you should see a useful (green on black) traceback…

  2. You may have a missing package. To find the missing package, run the script (see Script below)…


I am working on Salt states to install ‘shiny’ R package from CRAN: https://gitlab.com/kb/salt/commit/ccecedb5f3d9008118a40f5e316e4888b1e0a85b

Some useful bash commands:

# is a package installed?
R --silent -e "packageVersion('shiny')"

# install a package
R --silent -e "install.packages('tidyverse', repos='https://cran.rstudio.com/')"

# remove a package (not sure what ``--silent`` is doing)?
R --silent -e "remove.packages('shiny')"


To run a script:

sudo -i -u shiny
Rscript /srv/shiny-server/app.R


cat(file=stderr(), "loading...\n")

Shiny Server


I can’t find a way to install jsonlite as a user, so do the following:

sudo -i -u shiny
# run R
# at the R prompt
install.packages('jsonlite', dependencies=TRUE, repos='https://cran.rstudio.com/')
# accept the defaults


To add logging, edit:


And add a SHINY_LOG_LEVEL e.g:


Reload the daemon and re-start the service:

systemctl stop shiny-server
systemctl daemon-reload
systemctl start shiny-server

If you want to preserve_logs (as suggested in several forums) add preserve_logs as the very first line in the shiny-server.conf file:

# /etc/shiny-server/shiny-server.conf
preserve_logs true;
# Instruct Shiny Server to run applications as the user "shiny"
run_as shiny;


Adding preserve_logs didn’t seem to change the logging for me.