I have a shiny app that reads a table from GitHub. My aim is that when anyone who uses the app and edit the table, given they have access to the repository should be able to save the changes and push it to GitHub using an action button. How would I integrate a GitHub API as there is not much information online using it in R programming. The server side of the app at the moment is as follows:

  server = function(input, output, session) {
  # Constructs the table. Contains design and size code. 
  output$x1 = renderDT(x, selection = 'single', editable = TRUE,
                       class = 'cell-border stripe',
                       extensions =c('FixedColumns'),
                       options = list(scrollX = TRUE,
                                      fixedColumns = TRUE,
                                      fixedHeader = TRUE,
                                      fixedHeader = TRUE,
                                      deferRender = TRUE,
                                      scrollY = 400,
                                      scroller = TRUE
                       ))
  
  #Creates a proxy of the table visible 
  proxy = dataTableProxy('x1')
  
  #Replaces the old table with the edited data however does not save it. Need to click save
  observeEvent(input$x1_cell_edit, {
    info = input$x1_cell_edit
    str(info)
    i = info$row
    j = info$col
    v = info$value
    x[i, j] <<- v
    #To enforce the same target type as the old value use the below code and delete above
    #x[i, j] <<- DT::coerceValue(v, x[i, j])
    replaceData(proxy, x, resetPaging = FALSE) })  

  #Saves the edited table
  observeEvent(input$save,
               {write.csv(x, "...", row.names=FALSE)
                shinyalert(title = "Saved!", type = "success")
               })
  
  #Pushes the edited changes onto github. Takes a little longer than saving 
  observeEvent(input$push,
               {repo <- repository()
               status()
               add(repo,"*")
               commit(repo,"commiting through R and using system2 to push")
               #system2() allows git command to be directly run in r code 
               system2("git", "push origin master", stdout = TRUE, stderr = TRUE)
               shinyalert(title = "Pushed to Github", type = "success")
               })
}
)

At the moment this works for me in my Rstudio. However the aim is to publish this on Rstudio connect, therefore require a GitHub API to allow other users to save too. Any relevant code, insights or direction to a documentation will be great.

0

There are 0 answers