<p><div><div><div><div data-show-faces="false" data-height="21" data-width="100" data-layout="button_count" data-send="true" data-href="https://www.r-bloggers.com/setting-up-a-version-controlled-shiny-server/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://rmhogervorst.nl/cleancode/blog/2018/02/06/setting-up-a-version-controlled-shiny-server.html"> Clean Code</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>Last week I set up a shiny server, it was relatively easy! But I wanted something more, a way to make changes on my local computer and push it to the server.</p>
<p>Shiny server (I used the open source version) has multiple installers provided by RStudio.</p>
<p>The installers for shiny-server create a user shiny and installs all the services needed.</p>
<p>I used a guide specific for my version of linux to install shiny-server and combined it with two other guides to make it version controlled.</p>
<p>I have added the instructions to this <a rel="nofollow" href="https://gist.github.com/RMHogervorst/9d88ebff914b66b984ede8e78876c92f" target="_blank">github gist</a> but you can also follow along.</p>
<h3>Server setup</h3>
<p>After you’ve installed shiny-server, the server serves all apps in ‘/etc/shiny-server’ but I really don’t like to scp into the server to upload files, I’d rather work on my computer, put everything under version control and push the changes to the server. That way I can easily revert my changes if something fails and I don’t lose work.</p>
<p>I’ve used Dean Atalli’s <a rel="nofollow" href="https://deanattali.com/2015/05/09/setup-rstudio-shiny-server-digital-ocean/" target="_blank">excellent guide to setting up a server on digital ocean</a> but I’ve modified a small part. He is using github to push his changes and then pulls from github to his server.<br>
I was in a situation where I did not have access to github and I wanted a slightly simpler setup.</p>
<p>I created a bare repository on the server (that accepts my changes and responds just as github would, except the pretty website features) and used a git-hook. The files in the bare repo are not laid out in the same way as in the original files (on my computer) so I have to do something with that.</p>
<p>A git hook is something that runs before, during or after you change a repo (it hooks into git). It is a simple shell script that (in my case) runs after a change is made in the repo and executes a command. After a change this ‘post-receive’-hook checks out the latest branch and moves it to ‘/etc/shiny-server/’.</p>
<p>So the set up is like <a rel="nofollow" href="http://toroid.org/git-website-howto" title="I modified this to make it apply to shiny-server" target="_blank">this</a> :</p>
<div>
<div>
<pre><code>/home/shiny/shiny.git
/etc/shiny-server/
/all the other folders in a linux system
</code></pre>
</div>
</div>
<p>You move into the shiny.git folder (no real need to use that extension, but it is common) and go to the .git folder. inside the folder you add and modify a file called post-receive like this:</p>
<div>
<div>
<pre><code><span>#!/bin/sh</span>
GIT_WORK_TREE <span>=</span> /srv/shiny-server git checkout <span>-f</span>
</code></pre>
</div>
</div>
<p>You also need to tell the server that this file ‘post-receive’ may be executed. by ‘chmod +x hooks/post-receive’.</p>
<h3>setting up you local computer.</h3>
<ul>
<li>(optional) Move the files from the server /etc/shiny-server/ to you computer so you can always revert back to the basic settings.</li>
<li>make sure you have a ssh key set up (this is safer to work with than username password)</li>
<li>we are going to move the ssh key of your computer to the list of accepted ssh keys in the server.</li>
<li>make a repo which will be your root folder on the server, meaning this folder will be mirrored in ‘/etc/shiny-server/’ so shiny-server could be a good name.</li>
</ul>
<h3>a few changes on your server</h3>
<ul>
<li>add your ssh key to ‘~/.ssh/authorized_keys’ on the server</li>
</ul>
<h3>back to your local computer</h3>
<ul>
<li>
<p>add a remote to your repo: ‘git remote add shinyserver ssh://shiny@server.example.org/home/shiny/shiny-repo.git’</p>
</li>
<li>git remote add: <em>add a remote</em></li>
<li>shinyserver <em>the name of that remote</em></li>
<li>ssh:// <em>make a ssh connection to</em></li>
<li>shiny@adres/ <em>the user shiny on server</em></li>
<li>home/shiny/shiny-repo.git <em>to the folder shiny-repo in user shiny</em></li>
</ul>
<p>push to repo $ git push shinyserver +master:refs/heads/master</p>
<h3>This should now work</h3>
<p>Good luck!</p>
<p>(I did not have access to the server while I wrote this, so I could have made mistakes, PR me with hints and answers or open an issue, alternatively: reach me on twitter @rmhoge)</p>
<p><a rel="nofollow" href="http://rmhogervorst.nl/cleancode/blog/2018/02/06/setting-up-a-version-controlled-shiny-server.html" target="_blank">Setting up a version controlled shiny-server</a> was originally published by at <a rel="nofollow" href="http://rmhogervorst.nl/cleancode" target="_blank">Clean Code</a> on February 06, 2018.</p>
	<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="http://rmhogervorst.nl/cleancode/blog/2018/02/06/setting-up-a-version-controlled-shiny-server.html"> Clean Code</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a rel="nofollow" href="https://www.r-project.org/" title="The R Project for Statistical Computing">R</a> news and <a rel="nofollow" href="https://www.r-bloggers.com/search/tutorial" title="R tutorials">tutorials</a> on topics such as: <a rel="nofollow" href="https://www.r-bloggers.com/search/data%20science" title="Data science">Data science</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data" title="Big Data">Big Data, <a rel="nofollow" href="https://www.r-users.com/" title="R jobs">R jobs</a>, visualization (<a rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2" title="ggplot and ggplot2 tutorials">ggplot2</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/boxplot" title="Boxplots using lattice and ggplot2 tutorials">Boxplots</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/map" title="Maps and gis">maps</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/animation" title="Animation in R">animation</a>), programming (<a rel="nofollow" href="https://www.r-bloggers.com/search/RStudio" title="RStudio IDE for R">RStudio</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/sweave" title="Sweave and literate programming">Sweave</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX" title="LaTeX in R">LaTeX</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/SQL" title="SQL and databases">SQL</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/eclipse" title="Eclipse IDE for R">Eclipse</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/git" title="git and github, Version Control System">git</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/hadoop" title="Large data in R using Hadoop">hadoop</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping" title="Web Scraping of google, facebook, yahoo, twitter and more using R">Web Scraping</a>) statistics (<a rel="nofollow" href="https://www.r-bloggers.com/search/regression" title="Regressions and ANOVA analysis tutorials">regression</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/PCA" title="principal component analysis tutorial">PCA</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/time+series" title="Time series">time series</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/trading" title="finance trading">trading</a>) and more...
<img width="1" alt="" src="http://feeds.feedburner.com/~r/RBloggers/~4/bxehGAfYMWo" height="1"></a></div>