Skip to content

Instantly share code, notes, and snippets.

@diplodata
Created September 14, 2017 08:23
Show Gist options
  • Save diplodata/3aa957dea598552ae8df1686525dd5aa to your computer and use it in GitHub Desktop.
Save diplodata/3aa957dea598552ae8df1686525dd5aa to your computer and use it in GitHub Desktop.
Shiny script to automate commit push to a Github repo

You can configure a Shinyapps app to run a script that pushes a commit to a Github repo. Just:

  • set up a Github access token with minimal permissions, e.g. Settings / Personal access tokens / Generate new token (tick repo permissions)
  • deploy script to shinyapps.io, eg. rsconnect::deployApp(account = 'accountname')
  • trigger it with a remote call (eg. crontab) like curl https://accountname.shinyapps.io/app_name/index.php
require(shiny)
library(git2r)
token = "xxx"
system('git clone https://github.com/accountname/reponame.git', intern = F)
cred = cred_user_pass(username = 'accountname', password = token)
repo = repository('reponame')
config(repo, user.name="accountname", user.email="xxx@xxx.com")
writeLines(as.character(Sys.time()), file.path(repo@path, "test.txt"))
add(repo, ".")
commit(repo, as.character(Sys.time()))
push(repo, "origin", "refs/heads/master", credentials = cred)
unlink('test', recursive = T)
server = function(input, output){
output$confirmation = renderText('done')
}
ui <- basicPage(
textOutput('confirmation')
)
shinyApp(ui, server)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment