Skip to content

Instantly share code, notes, and snippets.

@RMHogervorst
Last active February 19, 2018 12:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RMHogervorst/9d88ebff914b66b984ede8e78876c92f to your computer and use it in GitHub Desktop.
Save RMHogervorst/9d88ebff914b66b984ede8e78876c92f to your computer and use it in GitHub Desktop.
description of commands and steps taken to create a version controlled shiny-server

link to blogpost

This is a mix of the excellent guide by Dean Attali and a setting up a webserver guide I found here. I mean hire that guy for your shiny jobs!

Today [2018-02-19] I found another example (a bit more advanced) of deployment from git

A version controlled shiny-server

The final version of this server has shiny-server installed and working and can be controlled from your own computer.

There are some steps that need to be done on your computer and some on the server, it is relatively easy to work on your local computer and have an ssh window open to execute the steps on your server.

steps:

on the server

  • install shiny-server
  • install git
  • create empty and bare git-repo
  • copy the basic files from the server to your local computer (optional)

on your computer

  • create ssh key if you do not have one on your local computer
  • create local repo

on the server

  • add key to accepted list on server
  • create git-hook on empty bare repo

on your computer

  • add server as remote
  • push to repo
  • done!

prerequisites

In this gist I assume you have already ran the installer for shiny-server and before that installed all the necessary R packages. If you install all the packages as super user, they are available for every user, if you don't install them as superuser, install them under the user shiny.

setting up the repo on the server

I assume shiny-server is installed and the user shiny has not external password

  • install git according to your system (on ubuntu sudo apt install git )

  • create empty and bare git-repo

  1. navigate to the folder '/home/shiny'
  2. be user shiny (su shiny)
  3. create a folder where you will connect to mkdir shiny-repo.git
  • copy the basic files from the server to your local computer (optional)

make your local version of the server

  • create ssh key if you do not have one on your local computer (this is different for every system)
  • create a local repo : something like shiny-repo

you could already add a basic shiny app in a folder inside shiny-repo Don't ever for the love of all you love, put a .Rmd file in the root of this folder, it took me 8 hours to debug that issue

continuouing on your server

  • add key to accepted list on server: you need to add your key to '~/.ssh/authorized_keys'
  • create git-hook on empty bare repo
  1. move into the repo 'cd /home/shiny/shiny-repo.git'
  2. create the git hook and make it executable (you can make this 2 steps, f.i. 'nano hooks/post-receive' and adding the #!/ ... etc.)
$ cat > hooks/post-receive
#!/bin/sh
GIT_WORK_TREE=/etc/shiny-server git checkout -f
$ chmod +x hooks/post-receive

On your computer again

  • add server as remote
  1. move into your repo on your local computer 'cd shiny-repo'
  2. add a remote to your repo 'git remote add shinyserver ssh://shiny@server.example.org/home/shiny/shiny-repo.git'
  • push to repo $ git push shinyserver +master:refs/heads/master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment