如何在 r shiny 中使用 r handsontable 下载 table?

How to download an table using rhandsontable in rshiny?

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

#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())
 })

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

ui.R 中的动作按钮:

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