部署时使用 unzip() 在 R Shiny 中解压缩文件失败 [英] Unzipping a file in R Shiny using unzip() fails when deployed

查看:30
本文介绍了部署时使用 unzip() 在 R Shiny 中解压缩文件失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我闪亮的应用程序的 www 文件夹中解压缩一个压缩的 .mdb 文件,查询它的数据,然后将其删除.Unzip() 在我的本地机器上工作,但是当我在 Shinyapps.io 上部署应用程序时,解压缩文件时出现问题.因为我无法 read.table() 生成的文件(它是一个 .mdb),我认为 unz() 不会工作.

I'd like to unzip a compressed .mdb file in the www folder of my shiny app, query it for data, and then remove it. Unzip() works on my local machine, but when I deploy the app at shinyapps.io, it has issues unzipping the file. Because I'm not able to read.table() the resulting file (it's an .mdb) I don't think unz() will work.

此代码在我的本地机器上运行时有效

This code works when run on my local machine

服务器:

require(shiny)    

shinyServer(function(input, output) {

   observeEvent(input$run,{ #Run Button

     dbName=unzip('www/test.zip', list=T)
     output$name=renderText({
        paste(dbName[1])
     })

     db=unzip('www/ttt.zip', exdir='www', unzip=getOption("unzip"))
     test1=read.csv(db) #.csv for simplicity, but my problem uses a .mdb
     file.remove(db)

     output$testcount=renderText({
        paste(sum(test1))
     })

  })#/Run Button  
})#/SS

用户界面:

shinyUI(
  sidebarLayout(
      sidebarPanel(width=3,

           h5('ZIP test'),                                           
           p(align="left", 
              shiny::actionButton("run", label = "Run!")
           ),                                           
           textOutput(outputId = "name"),
           textOutput(outputId = "testcount")                                           
      ),

      mainPanel(width=9,
           plotOutput(outputId = "probs",height = "550px")
      )                              
  )
)

但上传到 Shinyapps.io 时失败.

But fails when uploaded to Shinyapps.io.

知道我在这里做错了什么吗?我试过直接传递文件路径,并使用 unzip= 选项,但无济于事.如果我删除第二个调用,它会告诉我名字就好了,但是如果我尝试解压缩文件,它会中断.

Any idea of what I'm doing wrong here? I've tried passing the file path directly, and messing with the unzip= options, but to no avail. If I remove the second call, It will tell me the name just fine, but if I try to unzip the file, it breaks.

感谢任何帮助!

编辑

我可以通过删除 exdir='www', unzip=getOption("unzip") 并在根目录中查找文件来使其工作:test1=read.csv('file1.csv')

I was able to get it to work by removing exdir='www', unzip=getOption("unzip") and just looking for the file in the root directory: test1=read.csv('file1.csv')

推荐答案

我在 Shiny-server 上使用 unzip(),每次调用该函数时,.zip 的内容都会保存在应用程序的根目录中.我认为这是 Shinyapps.io 的问题.

I'm using unzip() on shiny-server and everytime the function is called the content of the .zip is saved in the root directory of the app. I asume thats a problem for shinyapps.io.

在文档中,您只能从我阅读的内容中使用exdir"指定文件所在的位置.

In the documentation you can only specify the location where the file is with 'exdir' from what I read.

这篇关于部署时使用 unzip() 在 R Shiny 中解压缩文件失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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