上传到 Shiny 服务器后在 R 中解压缩文件 [英] unzip file in R after uploading in Shiny server

查看:26
本文介绍了上传到 Shiny 服务器后在 R 中解压缩文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在我们的本地服务器上使用 Shiny,以构建允许用户上传包含 ESRI shapefile 和相关文件的 .zip 文件的应用程序.Shiny 服务器的 fileInput 可以获得数据,当它这样做时,它会将它存放在一个临时目录中 &文档名称.该文件名似乎总是一个相当通用的0".如果我手动尝试解压缩文件0",它会起作用.但是,如果我尝试使用 R 函数 unz(我认为它应该可以工作)以编程方式执行此操作,则会失败,错误消息是它无法打开 zip 文件 '0".我不知道为什么.有人可以帮忙吗?

I am trying to use Shiny on a local server of ours, to build an app that allows the user to upload a .zip file containing an ESRI shapefile and associated files. Shiny server's fileInput can obtain the data, and when it does so it sotres it in a temporary directory & filename. That filename seems to always be a rather generic "0". If I by hand try to unzip file "0" it works. But if I try to do it programmatically with the R function unz (which I gather should work) it fails, the error message is that it 'cannot open zip file '0'. I"m not sure why. Can anyone help?

代码如下:

shinyServer(function(input, output) {

mySHPdata <- reactive({
inFile <- input$file1

if (is.null(inFile))
  return(NULL)
print((inFile$datapath))

data<-read.table(unz(basename(inFile$datapath), "testme.shp"))

必须一一提取相关文件,所以这里我只是说明尝试打开其中之一.有人明白为什么这不起作用吗?

One has to extract the relevant files one by one, so here I am just illustrating attempting to open one of them. Anyone see why this does not work?

推荐答案

不应该是 basename(inFile$datapath),只要 inFile$datapath,否则R 不知道在哪里可以找到 0 文件.

It shouldn't be basename(inFile$datapath), just inFile$datapath, or else R doesn't know where to find the 0 file.

这篇关于上传到 Shiny 服务器后在 R 中解压缩文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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