I want to create a GUI using shiny to take 5 files as an input. Once I have uploaded these files, I want them to be saved in a particular Folder whose destination is known by me. Can we do this? If yes, how? Thank You.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Well, kind of. You can use observer to copy the file on upload:
library(shiny)
shinyApp(
ui=shinyUI(bootstrapPage(
fileInput("upload", "Upload", multiple = FALSE)
)),
server=shinyServer(function(input, output, session){
observe({
if (is.null(input$upload)) return()
file.copy(input$upload$datapath, "/some/other/path")
})
})
)
Not that I am using file.copy
and not file.rename
to avoid problems when the destination is located on a different device than the temporary directory.
回答2:
In addition to the answer by zero323, Use file.copy
as below if you want to overwrite the old uploads with new ones during each re-run of your app:
file.copy(..., recursive= TRUE)
(I wanted this in my app but it took me a whole lot of time to figure this out as I was a newbie at this)