Deployment of Shiny Apps from Rstudio to own open-source Shiny server

rstudio

#1

Hi all

what is the optimal deployment workflow given the next situation:

  • I have set own open source Rstudio server with Shiny server on Ubuntu, used this great AMI from Louis Aslett if someone interested
  • I use RStudio to write the code, do it both on local PC and now can do it at server. The code is sitting in ~/myproject folder
  • There is a Git repository that I use to keep the code on server and local PC in sync
  • With my set-up Shiny Apps sits in a separate folder on server like ~/ShinyApps (ideally with sub-folder, but I haven't figured out how to make it work yet)

So at the moment I edit the code in one folder (myproject) and when I need to deploy an app I have to manually copy the Shiny app part of code (App.R) to ShinyApps folder.

Is there any better workflow possible? Without need to manually copy the app file every time I want to make update accessible through web.

I see that Rstudio has publishing button, but it seems to work with its own paid services only.


#2

I also have the same struggle. I use gitLab to sync between local R code and server code. One way is we have the same directory and subdirectory structure (relative to root) in both the server and local. And we always rename our final code as app.R locally before a git push and git pull from server.


#3

In my work flow I have git initialized in the default /srv/shiny-server folder and pushed to gitHub, then I clone the repository in my laptop (windows), initialize a RStudio project and develop apps within its own folder inside the shiny-server project, so anytime I want apps (or changes) to be live on the web, I just do git push on my laptop and git pull on the server.


#4

Hi,

I have a different approach. I git only the rstudio code. It includes a deploy script that is responsible of pushing the required files on shiny server. I tend to prefer having only my running files on a production server. So I am willing to take the extra time required to pick only what shiny server need. A script is rather easy and clean.

One issue is to keep both R version and package in sync between rstudio server and shiny server. if they are on the same server, you can make them use the same library. Another issue is that shiny server would keep on serving an old version as long as a session is still active. So might have to restart the service to force a refresh.

Regards,

jm


#5

On your last line I think the shiny server picks up the latest app.R without having to restart the server. When you say

session is still active

I hope you meant the client-server session. Just a browser refresh at the client side should be sufficient and shiny server will re source the app.R.

I am intrigued by your methodology of writing a script that loads the correct files. Would you please elaborate a little about that script? What does it check and how does it decide the files to be transferred if there is a new data file etc? What if there are data files that are updated on the server and are needed back on the local machine? etc.


#6

I also only have app.R and global.R files on server, my .gitignore file takes care of that for me, so I can simply do

sudo git add .
sudo git commit - m "..."
sudo git push origin master
#And in the server
sudo git pull origin master

#7

The issue about refresh of an application is better explained here:
http://docs.rstudio.com/shiny-server/#restarting-an-application

Old connections still linked to an R session spawned with your old code, will still see the old code. If you refresh the browser, it won't connect you to a new session. That's at least my experience with learnR applications that keep track of user progress server side. Pure shiny apps might behave differently.

Our script is a basic one. First remove everything in the target folder, then rsync the new content there. Adjust permissions as required. Not very elegant but quite simple.