如何在rshiny中使用rhandsontable下载表格?

时间:2017-12-04 15:21:10

标签: r shiny handsontable

我编写了以下服务器代码来显示内容。如何在编辑动手表后下载文件

#server 
 value <- eventReactive(input$file, {
   theFile <- input$file
   if(is.null(theFile)) {
    return(NULL)}
 file.rename(theFile$datapath,paste(theFile$datapath, ".xlsx", sep=""))
 Data <- read_excel(paste(theFile$datapath, ".xlsx", sep = ""), 1) 
 Data
})

output$contents <- renderRHandsontable({
  rhandsontable(value())
 })

1 个答案:

答案 0 :(得分:1)

我会在ui.R中添加一个actionButton并用它来保存文件。

ui.R中的actionButton:

actionButton("savefile", "Save", width = '100%')

要在server.R中保存文件:

observeEvent(input$savefile,
                {

                   if (!is.null(isolate(input$contents)))
                   {
                       #Convert to R object
                       x <- hot_to_r(isolate(input$contents))
                       write.table(x, file = 'employee_input.txt', row.names=FALSE, quote = TRUE, sep = ",",
                       na = "NA", dec = ".")
                   }
                }
            )