Skip to content

Instantly share code, notes, and snippets.

@stephlocke
Last active April 2, 2024 09:21
Show Gist options
  • Star 18 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save stephlocke/c3299992ef3ac3efe1f978bd1cb0b4b2 to your computer and use it in GitHub Desktop.
Save stephlocke/c3299992ef3ac3efe1f978bd1cb0b4b2 to your computer and use it in GitHub Desktop.
Demo shiny app for multiple file uploads and a single read step
library(shiny)
library(data.table)
ui <- fluidPage(
titlePanel("Multiple file uploads"),
sidebarLayout(
sidebarPanel(
fileInput("csvs",
label="Upload CSVs here",
multiple = TRUE)
),
mainPanel(
textOutput("count")
)
)
)
server <- function(input, output) {
mycsvs<-reactive({
rbindlist(lapply(input$csvs$datapath, fread),
use.names = TRUE, fill = TRUE)
})
output$count <- renderText(nrow(mycsvs()))
}
shinyApp(ui = ui, server = server)
@FEI-JIANG
Copy link

This is a very good example to load multiple csv/txt files. But is it possible to load multiple excels which have multiple sheets?

@Krithika-Bhuvan
Copy link

Thanks. Could you provide an example to load multiple excel files ? At the moment each excel file has only one sheet

@stephlocke
Copy link
Author

@KrithikaB472 To load excel files you would change fread to readxl::read_excel
@FEI-JIANG For multiple sheets in multiple excel docs you will need a two step process - one to get a list or data.frame of workbooks and the sheets (readxl::list_sheets) and then the lapply (or a {purrr} equivalent) to do readxl::read_excel

@JulianStopp
Copy link

Thanks a lot for the code example. I tried to use it for multiple .tab files and it works nice. But one question - is it possible to save the names of the original files within the dataframe as a column? I tried ti use id.col which works outside of shiny but with that code only adds numbers.

@mjcampy
Copy link

mjcampy commented Jun 23, 2020

Anyway to make this work for multiple .zip files? with a few .csv inside each?

@Zwiiiii
Copy link

Zwiiiii commented May 5, 2022

Thank you very much !!!!

@piercefa
Copy link

piercefa commented May 2, 2023

I added a step to view the data in a table, but it seems that the files (xlsx) are not actually combining. I am simply uploading a new file each time. Is there a step I am missing that combines each file I upload? Thank you so much for this demo!

@stephlocke
Copy link
Author

You may need to ctrl+click the files @piercefa you want to upload when in your file explorer window that pops up

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment