Here is the reproducible data:
file1 <- data.frame(animal = c('cat','dog','horse'), w = c(10,20,30)) file2 <- data.frame(animal = c('pig','dog','bat'), w = c(11,22,33)) file3 <- data.frame(animal = c('dog','eagle','horse'), w = c(110,220,330)) write.csv(file1, 'foobar_TEST_1.csv') write.csv(file2, 'foobar_TEST_2.csv') write.csv(file3, 'foobar_TEST_3.csv') I would like to upload all 3 files and if the values under 'animal' column are duplicates, rename only the duplicates using the last part of file names. From our data: dog, dog_TEST_2, dog_TEST_3, horse, horse_TEST_2
Here's the Shiny code and ideally, I'd like to implement the code in the reactive():
ui <- fluidPage( sidebarPanel( fileInput(inputId = "animal", label = "Upload Multiple Files", multiple = T, accept = c("text/csv", "text/comma-separated-values,text/plain", ".csv"))), mainPanel( DT::dataTableOutput("table1"))) server <- function(input, output, session) { data <- reactive({ req(input$animal) inFile <- input$animal$datapath df <- lapply(inFile, function(y){ files <- read.csv(y, header=TRUE) }) final <- do.call(rbind, df) list(final = final) }) output$table1 <- DT::renderDataTable({ final <- data()$final datatable(data = final) }) } shinyApp(ui = ui, server = server) 