问题
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
Server:
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
ui:
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")
)
)
)
But fails when uploaded to Shinyapps.io.
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.
Any help is appreciated!
EDIT
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')
回答1:
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.
In the documentation you can only specify the location where the file is with 'exdir' from what I read.
来源:https://stackoverflow.com/questions/33225228/unzipping-a-file-in-r-shiny-using-unzip-fails-when-deployed