How to extract name of uploaded file


#1

cc @edgararuiz

How can I extract the name of the uploaded file? I uploaded the file using

fluidRow(
                   column(width = 10, fileInput("file", "upload the file", accept = ".tsv", placeholder = "No file selected", multiple = FALSE))
                 )
observeEvent(input$value,{
   if(input$value == 'Y'){
     inFile = input$file
     inFileName = inFile$name
     result <- glycoPipe("PARAMS.tsv")
     returnedValue = result$params
     output$box <- renderText({
       paste("Your result is ", returnedValue)
     }
     )
    }
  })

I know the function call works because when I sen the actual file name i get the expected results. It does not work when I use input$file$name instead of “glycoPipe_PARAMS_TEMPLATE.tsv”


#2

In the code,where is inFileName being used after is loaded ?


#3

This is

UI <- fluidPage(

 fluidRow(
                   column(width = 10, fileInput("file", "upload the file", accept = ".tsv", placeholder = "No file selected", multiple = FALSE))
                 )
                            )

#This is the function outside UI function and server function()

glycoPipe <- function(PARAMSfullFile=NULL){

params <- checkParams(filename)

list(params = params)  

}
#This function is defined in a script called utilities.R which is found in the utilityFoler specified in 
#the source statement
params <- checkParams(filename)

}

in utilities script the funcion is:

checkParams <- function(PARAMSfullFile){
params = PARAMSfullFile
return(params)

}

This is the server function:

server <- function(input, output, session){
  source("UtilityFoler/utilities.R", chdir = TRUE)

observeEvent(input$value,{
   if(input$value == 'Y'){
     inFileName = input$file$name
     result <- glycoPipe("glycoPipe_PARAMS_TEMPLATE.tsv")
     returnedValue = result$params
     output$box <- renderText({
       paste("Your result is ", returnedValue)
     }
     )
    }
  })

#4

Right, but I don’t see what does the code does with the file path other that load the inFileName variable.


#5

Once the uploaded file name is received by checkParams <- function(PARAMSfullFile = NULL) I will use it to read the file from the directory. This file has to be compared with another file which is not input by the user, but it is stored in the working directory. I do not need for params to be returned, but the reason why I return it in the script and capture it in the server fuction inFileName = result$params is because I want to check that the parameter is taken by the function and therefore returned

ckeckParams(PARAMSfullFile){
 params = PARAMSfullFile

read.delim(params)
read.delim("string= other file")
compare the two files.
return(params)
}

#6

The problem that I see is that once the user selects ‘Y’ from the fileChoose menu, the file is selected and then uploaded, so the file cannot be stored in the input$file$name until it has been selected and uploaded and I do not know how to specify save the input file name after selection and upload.


#7

inFileName = input$file$name is not reading the file name because if I render the text:

output$box <- renderText({
       paste("Your result is ", inFileName)
     }

the file name is not displayed in the GUI


#8

I am getting this warning
"Warning in scan(file = file, what = what, sep = sep, quote = quote, dec = dec, :
EOF within quoted string"

I also get:
Listening on http://127.0.0.1:6657
NULL


#9

input$file1 will be NULL initially. After the user selects

# and uploads a file, it will be a data frame with 'name',
# 'size', 'type', and 'datapath' columns. The 'datapath'
# column will contain the local filenames where the data can
# be found

so the problem is how to extract whether file has been selected and uploaded or not.


#10

This works because in this case the function is called after the file is uploaded and therefore the file name can be read.

server <- function(input, output, session){
  source("UtilityFoler/utilities.R", chdir = TRUE)
  
  output$contents <- renderTable({
    inFile = input$file
    inFileName = input$file$name
    if(is.null("inFile")){
      return()
    }
    
    req(inFile)
    validate(
      need(file_ext(inFile) %in% c(
        'tsv'
      ), "Wrong File Format. The selected file is not a valid tab-separated PARAMS file try again. If
      you do not have a parameters.tsv file in your directory stop clycoPipe create a file and re-start glycoPipe"))
      read.table(inFile$datapath, quote = "", sep = '\t')
      result <- glycoPipe(inFileName)
      returnedValue = result$params
      paste("Your result is ",returnedValue)
  })

#11

That’s great news! I’m glad you were able to work it out