We recently enabled custom buildpacks on GOV.UK PaaS after requests by members of the data science community who want to deploy shiny apps.
Although our team is not able to provide official support for R/shiny buildpacks, I was able to get a simple shiny app working, with some help from Adam Robinson, who commented on a previous version of this gist. Thanks Adam!
I'm coping the data science community will be able to try using PaaS to deploy shiny apps and share what they learn and any buildpack improvements they make.
After a few false starts I managed to get something working.
I found a page explaining how to push R apps which told me to use this buildpack.
I tried the "hello world example".
I copied some files from the example shiny app in the buildpack source that I thought would be needed and tried pushing the app.
git clone https://github.com/rstudio/shiny-examples.git
git clone https://github.com/wjjung317/heroku-buildpack-r.git
cd shiny-examples/001-hello
cp ../../heroku-buildpack-r/test/shiny/init.r .
cp ../../heroku-buildpack-r/test/shiny/Procfile .
cp ../../heroku-buildpack-r/test/shiny/run.R .
cf push -b https://github.com/wjjung317/heroku-buildpack-r.git shiny-demo
I tried using the buildpack we were asked to support and I wasn't successful. You may have better knoweldge.
Enabled custom buildpacks.
git clone https://github.com/rstudio/shiny-examples.git
git clone https://github.com/beibeiyang/cf-buildpack-r.git
cd shiny-examples
cp ../cf-buildpack-r/init.r .
cf push -b https://github.com/beibeiyang/cf-buildpack-r.git -c "R -e shiny::runApp\('001-hello'\)" shiny-demo
...
** testing if installed package can be loaded
* DONE (sourcetools)
* installing *source* package ‘Cairo’ ...
** package ‘Cairo’ successfully unpacked and MD5 sums checked
0 of 1 instances running, 1 crashed
FAILED
Error restarting application: Start unsuccessful
TIP: use 'cf logs shiny-demo --recent' for more information
Excerpt from cf logs shiny-demo --recent
:
2017-06-26T15:12:22.45+0100 [APP/PROC/WEB/0]OUT Copyright (C) 2016 The R Foundation for Statistical Computing
2017-06-26T15:12:22.45+0100 [APP/PROC/WEB/0]OUT Platform: x86_64-pc-linux-gnu (64-bit)
2017-06-26T15:12:22.45+0100 [APP/PROC/WEB/0]OUT You are welcome to redistribute it under certain conditions.
2017-06-26T15:12:22.45+0100 [APP/PROC/WEB/0]OUT Type 'license()' or 'licence()' for distribution details.
2017-06-26T15:12:22.45+0100 [APP/PROC/WEB/0]OUT Natural language support but running in an English locale
2017-06-26T15:12:22.45+0100 [APP/PROC/WEB/0]OUT R is a collaborative project with many contributors.
2017-06-26T15:12:22.45+0100 [APP/PROC/WEB/0]OUT Type 'contributors()' for more information and
2017-06-26T15:12:22.45+0100 [APP/PROC/WEB/0]OUT 'citation()' on how to cite R or R packages in publications.
2017-06-26T15:12:22.45+0100 [APP/PROC/WEB/0]OUT Type 'demo()' for some demos, 'help()' for on-line help, or
2017-06-26T15:12:22.45+0100 [APP/PROC/WEB/0]OUT 'help.start()' for an HTML browser interface to help.
2017-06-26T15:12:22.45+0100 [APP/PROC/WEB/0]OUT Type 'q()' to quit R.
2017-06-26T15:12:22.58+0100 [APP/PROC/WEB/0]OUT > shiny::runApp(050-kmeans-example)
2017-06-26T15:12:22.78+0100 [APP/PROC/WEB/0]ERR Error in 50 - kmeans : non-numeric argument to binary operator
2017-06-26T15:12:22.78+0100 [APP/PROC/WEB/0]ERR Calls: <Anonymous> -> as.shiny.appobj
2017-06-26T15:12:22.78+0100 [APP/PROC/WEB/0]ERR Execution halted
2017-06-26T15:12:22.79+0100 [APP/PROC/WEB/0]OUT Exit status 1
The error in the output looked like this:
2017-06-26T15:55:39.17+0100 [APP/PROC/WEB/0]OUT R version 3.2.1 (2015-06-18) -- "World-Famous Astronaut"
2017-06-26T15:55:39.17+0100 [APP/PROC/WEB/0]OUT Copyright (C) 2015 The R Foundation for Statistical Computing
2017-06-26T15:55:39.17+0100 [APP/PROC/WEB/0]OUT Platform: x86_64-unknown-linux-gnu (64-bit)
2017-06-26T15:55:39.17+0100 [APP/PROC/WEB/0]OUT R is free software and comes with ABSOLUTELY NO WARRANTY.
2017-06-26T15:55:39.17+0100 [APP/PROC/WEB/0]OUT You are welcome to redistribute it under certain conditions.
2017-06-26T15:55:39.17+0100 [APP/PROC/WEB/0]OUT Type 'license()' or 'licence()' for distribution details.
2017-06-26T15:55:39.17+0100 [APP/PROC/WEB/0]OUT Natural language support but running in an English locale
2017-06-26T15:55:39.17+0100 [APP/PROC/WEB/0]OUT R is a collaborative project with many contributors.
2017-06-26T15:55:39.17+0100 [APP/PROC/WEB/0]OUT Type 'contributors()' for more information and
2017-06-26T15:55:39.17+0100 [APP/PROC/WEB/0]OUT 'citation()' on how to cite R or R packages in publications.
2017-06-26T15:55:39.17+0100 [APP/PROC/WEB/0]OUT Type 'demo()' for some demos, 'help()' for on-line help, or
2017-06-26T15:55:39.17+0100 [APP/PROC/WEB/0]OUT 'help.start()' for an HTML browser interface to help.
2017-06-26T15:55:39.17+0100 [APP/PROC/WEB/0]OUT Type 'q()' to quit R.
2017-06-26T15:55:39.27+0100 [APP/PROC/WEB/0]OUT > shiny::runApp(001-hello)
2017-06-26T15:55:39.43+0100 [APP/PROC/WEB/0]ERR Error in as.shiny.appobj(appDir) : object 'hello' not found
2017-06-26T15:55:39.43+0100 [APP/PROC/WEB/0]ERR Calls: <Anonymous> -> as.shiny.appobj
2017-06-26T15:55:39.43+0100 [APP/PROC/WEB/0]ERR Execution halted
2017-06-26T15:55:39.44+0100 [APP/PROC/WEB/0]OUT Exit status 1
Using beibeiyang/cf-buildpack-r
I've got a working version on Pivotal IO using the test app in this build pack. Steps as follows:
Open the yml file to change the name of the app as currently taken on Pivotal. I did this manually.
Push the app. Just need to use cf push as everything is defined in yml file.
Example: https://rshiny-test-app.cfapps.io:4443
Applying to other applications.
In this example the part thats make up the shiny app are:
To apply to another application we need to do the following:
To do this open the init.r file in any text editor. It should look like this:
We need to update the my_packages variable with all the packages used in the application.
For the demo app above these are as follows:
Update my_packages to the following:
Note: Be careful to use " not ” as ” will throw an r error.
Open the yml file to change the name of the app.
Push the app. Just need to use cf push as everything is defined in yml file.
Example: https://r-shiny-example-app.cfapps.io:4443