Shiney Dashboards

R/Shiny Installation with uzERP


Database Auth

Install postgresql dbd driver and enable modules

$ sudo apt-get update
$ sudo apt-get install libaprutil1-dbd-pgsql
$ sudo a2enmod proxy
$ sudo a2enmod proxy_http
$ sudo a2enmod dbd
$ sudo a2enmod authn_dbd


Add a new site config, e.g. /etc/apache2/sites-available/

<VirtualHost *:80>

    ProxyPass / http://localhost:3838/ retry=10
    ProxyPassReverse / http://localhost:3838/
    ProxyPreserveHost On

    DBDriver pgsql
    # password not needed for localhost
    DBDParams "host=localhost dbname=uzerp user=ooo-data"

    DBDMin  4
    DBDKeep 8
    DBDMax  20
    DBDExptime 300

    <ProxyMatch "/">
        # mod_authn_core and mod_auth_basic configuration
        # for mod_authn_dbd
        AuthType Basic
        AuthName "Dashboard"

        # To cache credentials, put socache ahead of dbd here
        AuthBasicProvider dbd

        # Also required for caching: tell the cache to cache dbd lookups!
        #AuthnCacheProvideFor dbd
        #AuthnCacheContext dashboard

        # mod_authz_core configuration
        Require valid-user

        # mod_authn_dbd SQL query to authenticate a user
        # Add the correct role id in the query below. Use hasrole.roleid in (1, 2) for multiple roles
        AuthDBDUserPWQuery "SELECT PASSWORD, users.username as USERNAME, EMAIL FROM users join hasrole on hasrole.username = users.username WHERE users.username = %s and hasrole.roleid = 2"

    <Location "/">
        # Pass the username, etc in request headers to Shiny
        RequestHeader set X-Proxy-REMOTE-USER %{AUTHENTICATE_USERNAME}e
        RequestHeader set X-Proxy-REMOTE-EMAIL %{AUTHENTICATE_EMAIL}e

    # Optional friendly 'unathorised' page to show when user auth fails
    #ErrorDocument 401 /srv/shiny-server/auth.html

    ErrorLog /var/log/apache2/dashboard.log

Install R and Shiny server on Ubuntu 14.04

Install R, Shiny, Shiny Server

$ sudo sh -c 'echo "deb trusty/" >> /etc/apt/sources.list'
$ gpg --keyserver --recv-key E084DAB9
$ gpg -a --export E084DAB9 | sudo apt-key add -
$ sudo apt-get -y install r-base
$ sudo su - -c "R -e \"install.packages('shiny', repos='')\""
$ sudo apt-get install gdebi-core
$ sudo apt-get install gdebi-core
$ wget
$ sudo gdebi shiny-server-

Install dashboard dependencies (note: postgresql-server-dev-9.3 required to compile RPostgreSQL)

$ sudo apt-get install postgresql-server-dev-9.3
$ sudo su - -c "R -e \"install.packages(c('RPostgreSQL', \
'DT', \
'data.table, \
'shinydashboard', \
'ggplot2', \
'lubridate'), repos='')\""

Upload Shiny app and Run

Upload shiny app to a directory in /srv/shiny-server

Enable site in Apache

$ sudo a2ensite
$ sudo service apache2 restart

The app should now be available at, use uzERP credentials to login.