3

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
    Are you sure that `basename(inFile$datapath)` is correct? Did you try to use `unz(inFile$datapath, "testme.shp")`? – sgibb Sep 25 '13 at 16:04

1 Answers1

5

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

Joe Cheng
  • 8,001
  • 42
  • 37
  • (Sorry, just saw sgibb's comment) – Joe Cheng Sep 25 '13 at 21:15
  • Thanks - I did try that, and it still did not work. But I gave up a bit easily, perhaps, as I decided a system call to an external file unzipper would give me more freedom for what I'm trying to do. And that worked! –  Sep 25 '13 at 21:41