【问题标题】:R Shiny: unzip doesn't output the correct file path in reactiveR Shiny:解压缩不会在反应中输出正确的文件路径
【发布时间】:2018-10-25 13:16:23
【问题描述】:

在一个闪亮的应用程序中,如果你点击打开文件对话框,它会运行这个反应函数:

data <- reactive({
    file <- input$file
    req(file)
    if (is.null(file)) {
        return(NULL)
    }
    fpath <- file$datapath
    if (endsWith(".zip", fpath)) {
        fpath <- unzip(zipfile = fpath, files = NULL, overwrite = TRUE)
    }
    data <- read.csv(fpath, header = TRUE)
    data
})

对于 CSV 文件,它按预期运行。对于 ZIP 文件,fpath 不会成为解压后的 CSV 的路径 - 它会保留为临时 ZIP 文件路径并导致 read.csv 函数出错。此代码在响应式之外按预期运行。每次尝试将调试代码插入此反应式或在调试器中单步执行都会被忽略。它不会打印到 stderr 等。

如何解压缩 ZIP 文件并读取 CSV 文件?这个article 没有完全回答这个问题。我认为 this article 中有一些东西,但我无法在我自己的上下文之外理解它。

【问题讨论】:

    标签: r debugging shiny reactive-programming unzip


    【解决方案1】:

    你有更完整的例子吗? 对我来说,它正在工作,只需将 if (endsWith(".zip", fpath)) 更改为 if (endsWith(fpath, ".zip"))

    【讨论】:

      猜你喜欢
      • 2017-08-01
      • 2015-07-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-05-11
      • 2019-01-23
      相关资源
      最近更新 更多