在Shiny中的压缩文件夹中下载多个csv文件 [英] Download multiple csv files in a zipped folder in Shiny

查看:578
本文介绍了在Shiny中的压缩文件夹中下载多个csv文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以指出我怎么能使这个下载zip功能在server.R工作?当我运行这个,我得到以下错误:

Can someone please point out how I can make this download zip function work in server.R? When I run this, I get the following error:


  • [1]/ var / folders / 00 / 1dk1r000h01000cxqpysvccm005p87 / T // Rtmps3T6Ua

  • 在write.csv中警告(datasetInput()$ rock,file =rock.csv,sep =,):
    尝试设置'sep'

  • 在write.csv中警告(datasetInput()$ pressure,file =pressure.csv,sep =,):尝试设置'sep'被忽略

  • 在write.csv中警告(datasetInput()$ cars,file =cars.csv,sep =,):
    尝试设置'sep'被忽略

  • [1]rock.csvpressure.csvcars.csv


    • 添加:rock.csv(缩小54%

    • 新增:pressure.csv(缩小42%)

    • 新增:cars.csv(缩小57%)

    • [1] "/var/folders/00/1dk1r000h01000cxqpysvccm005p87/T//Rtmps3T6Ua"
    • Warning in write.csv(datasetInput()$rock, file = "rock.csv", sep = ",") : attempt to set 'sep' ignored
    • Warning in write.csv(datasetInput()$pressure, file = "pressure.csv", sep = ",") : attempt to set 'sep' ignored
    • Warning in write.csv(datasetInput()$cars, file = "cars.csv", sep = ",") : attempt to set 'sep' ignored
    • [1] "rock.csv" "pressure.csv" "cars.csv"
      • adding: rock.csv (deflated 54%)
      • adding: pressure.csv (deflated 42%)
      • adding: cars.csv (deflated 57%)

      读取错误:9

      library(shiny)
      
      # server.R
      server <- function(input, output) {
      
        datasetInput <- reactive({
          return(list(rock=rock, pressure=pressure, cars=cars))
        })
      
        output$downloadData <- downloadHandler(
          filename = 'pdfs.zip',
          content = function(fname) {
            tmpdir <- tempdir()
            setwd(tempdir())
            print(tempdir())
      
            fs <- c("rock.csv", "pressure.csv", "cars.csv")
            write.csv(datasetInput()$rock, file = "rock.csv", sep =",")
            write.csv(datasetInput()$pressure, file = "pressure.csv", sep =",")
            write.csv(datasetInput()$cars, file = "cars.csv", sep =",")
            print (fs)
      
            zip(zipfile=fname, files=fs)
          },
          contentType = "application/zip"
        )
      
      }
      
      # ui.R
      ui <- shinyUI(fluidPage(
        titlePanel('Downloading Data'),
        sidebarLayout(
          sidebarPanel(
            downloadButton('downloadData', 'Download')
          ),
          mainPanel()
          )
        )
        )
      
      shinyApp(ui = ui, server = server)
      


    • 推荐答案

      我在Linux服务器上的RStudio服务器上工作。问题是RStudio不能自动找到zip可执行文件的路径。我不得不手动指定它。在命令行中, which zip 向我显示 / usr / bin / zip

      The top solution still wasn't working for me. I was working in RStudio Server on a Linux server. The problem was that RStudio couldn't automatically locate the path to the zip executable. I had to manually specify it. In the command line, which zip revealed to me /usr/bin/zip.

      所以,我只需要在我的代码顶部设置R_ZIPCMD环境变量。

      So, I just had to set the R_ZIPCMD environment variable at the top of my code.

      Sys.setenv(R_ZIPCMD="/usr/bin/zip")
      

      资料来源: zip()提及R_ZIPCMD。

      Source: The help file for zip() mentions R_ZIPCMD.

      这篇关于在Shiny中的压缩文件夹中下载多个csv文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆