闪亮的DownloadHandler无法保存.csv文件

时间:2018-12-17 09:09:03

标签: r datatable download shiny

我正在尝试将数据表下载到csv中。文件。不幸的是,即使开始下载,它仍会进行计算,并且不会保存数据。文件大小为8mb,我只能通过下载过滤后的数据集来解决此问题。我还尝试使用shiny.maxRequestSize=30*1024^2将下载大小设置为10 mb 我真的需要选项来保存整个数据集。如果有人可以提供一些见解,我将不胜感激(是的,我在浏览器中运行该应用程序)

我的ui函数如下所示:

tbl <- read.csv(file.choose(new = FALSE), header = TRUE, sep = ",", row.names=1)

ui <- navbarPage(
  title = "Data Table Options",

  #Tab with the dataset table
  tabPanel("Lot Dataset",
           div(h3("Download"), style = "color:blue"),
           helpText(" Select the download format"),
           radioButtons("type", "Format type:",
                        choices = c("Excel (CSV)", "Text (Space Separated)", "Doc")),
           helpText(" Click on the download button to download the Lot Dataset"),
           downloadButton("download_filtered", "Download Filtered Data"),   
           br(),
           br(),
           br(),
           DT::dataTableOutput("dt"),  #datatable
           ),
)

我的服务器功能如下:

server <- function(session, input, output) {

  #Increasing Downloadsize to 10MB
  options(shiny.maxRequestSize=10*1024^2)

 #render the datatable
  output$dt <- DT::renderDataTable({
    datatable(tbl, filter = "top", options =  list(
      lengthMenu = list(c(25, 50, 100, -1), c("25", "50", "100", "All")), 
      pageLength = 25)) 
  })
  #bottom panel with row indices 
  output$filtered_row <- 
    renderPrint({
      input[["dt_rows_all"]]
    })

  #file extension for download
  fileext <- reactive({
    switch(input$type,
           "Excel (CSV)" = "csv", "Text" = "txt", "Doc" = "doc")
  })

  #downloadHandler() for file download of Lot Dataset
  output$download_filtered <- downloadHandler(

    filename = function() {
      paste("MLdataset_test", fileext(), sep=".")  #filename
    },

    content = function(file) {

      #write tbl with filter
      write.csv(tbl[input[["dt_rows_all"]], ],
                file = file, row.names = F)
    }
  )
}

任何帮助表示赞赏!

0 个答案:

没有答案