2

我有一个从 GitHub 读取表格的闪亮应用程序。我的目标是,当任何人使用该应用程序并编辑表格时,如果他们有权访问存储库,应该能够保存更改并使用操作按钮将其推送到 GitHub。我将如何集成 GitHub API,因为在 R 编程中使用它的在线信息不多。目前应用的服务器端如下:

  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")
               })
}
)

目前,这在我的 Rstudio 中对我有用。然而,目的是在 Rstudio connect 上发布它,因此需要一个 GitHub API 来允许其他用户也保存。任何相关的代码、见解或文档指导都会很棒。

4

0 回答 0