Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Shiny fileInput Does Not Keep File Name

I am writing a program in Shiny where the user uploads a file and it saves to a specified folder. The method to do this is taken from this question's answer.

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")
        })
    })
)

When I execute this, I find that the file has its file name stripped when it is saved to the specified folder. The program that reads the files in the folder requires that the file name is left in tact. How can I accomplish that?

like image 942
black_sheep07 Avatar asked Sep 01 '25 17:09

black_sheep07


1 Answers

Change the file.copy line to

file.copy(input$upload$datapath, paste0("your_folder/", input$upload$name))
like image 63
Xiongbing Jin Avatar answered Sep 04 '25 06:09

Xiongbing Jin