shiny app File Upload: How can we save the files u

2019-02-07 13:33发布

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.

2条回答
ゆ 、 Hurt°
2楼-- · 2019-02-07 14:07

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)

查看更多
【Aperson】
3楼-- · 2019-02-07 14:11

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.

查看更多
登录 后发表回答