How to rename and fix user uploaded file in shiny

Hi i am a newbie at R and shiny.. i would like to rename the user upload file in my shiny app. I want R to work with a single name file regardless of that what ever the file name uploaded by user.

library(shiny)
ui<-fluidPage(
  titlePanel(title = h1(" ALPHA DIVERSITY", align="center")),
  sidebarLayout(
    sidebarPanel(
      fileInput("shared","Upload shared file:"),
      fileInput("upload","Upload design file:"),
        ),
    mainPanel
    (
      tabsetPanel(
          ))
server<-function(input,output,session){
  share<-reactive({
    req(input$shared)
    share1<-read.table(input$shared$datapath, header=T)
  })
  observe({
    if (is.null(input$shared)) return()
    file.rename(input$shared$datapath(shared), paste0(tempdir(),temp.txt))
  }
  
  # i tried this to save user uploaded file as a fixed name for further processing of that uploaded file but failed.

Can I ask, why you think you'll need this?
Usually you read the file via the infile argument directly into a (reactive) dataframe. So the name of the file isn't important as the name of the dataframe is defined.
file -> (temporary file on server?) -> infile -> dataframe.
If you need a physical copy of the file, you could however save the dataframe again to a file with known name.

filedata <- reactive({
    infile <- input$datafile
    if (is.null(infile)) {
      # User has not uploaded a file yet
      return(NULL)
    }
    read.csv(infile$datapath)
}) 

Thank you so much for your reply. Actually i am developing shiny app for alpha diversity analysis in mothur. User will upload a mothur output shared file and then mothur will run for alpha diversity and output file will be used for plot through ANOVA. The problem is that mothur will give output according to the file name uploaded by user like user may upload my.shared, mothur output will be my.summary.group. This name i need to write in shiny script to get mothur output. As i need this output file (my.summary.group) for ANOVA plot. I want to write the output file name one time in the script and what ever name file user will upload should be named as i already wrote in the script. Or any other possible solution if you can suggest. Thank you!

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.