unzip file in R after uploading in Shiny server

谁都会走 提交于 2019-12-23 16:33:52

问题


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?

here is the code:

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?


回答1:


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



来源:https://stackoverflow.com/questions/19009578/unzip-file-in-r-after-uploading-in-shiny-server

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!