Hello!
my ui.r allows the user to upload a file:
fileInput("file_input", label = "Upload your file")
Question: Is there a way to capture the name of the file the user ended up uploading?
Thank you very much!
Hello!
my ui.r allows the user to upload a file:
fileInput("file_input", label = "Upload your file")
Question: Is there a way to capture the name of the file the user ended up uploading?
Thank you very much!
Yes. You can extract it from the input$file_input
object. input$file_input
is a data frame so it should be familiar to work with.
The Details section of ?fileInput
describes the columns returned in the data frame. Note that the name
column only provides the name of the file, akin to basename
. It won't give the full path (which is usually unnecessary).
library(shiny)
shinyApp(
ui =
shinyUI(
fluidPage(
fileInput(inputId = "file_input",
label = "Select a file",
multiple = TRUE),
p("Class of `file_input`"),
verbatimTextOutput("file_input_class"),
p("Object"),
verbatimTextOutput("file_input_object"),
p("File Name"),
verbatimTextOutput("file_name")
)
),
server =
shinyServer(function(input, output, session){
output$file_input_class <-
renderPrint({
class(input$file_input)
})
output$file_input_object <-
renderPrint({
input$file_input
})
output$file_name <-
renderPrint({
input$file_input$name
})
})
)
Thank you very much!