dreamRs / datamods

Shiny modules to import and manipulate data into an application or addin
https://dreamrs.github.io/datamods/
GNU General Public License v3.0
138 stars 35 forks source link

Reading data from multiple sheets at once #45

Open Alik-V opened 2 years ago

Alik-V commented 2 years ago

Hi Victor, just discovered this, looks like another terrific package from you! I got a question regarding uploading data from an excel. Is it possible to upload data from multiple sheets at once?

pvictor commented 2 years ago

Hey Alik, thank you :) Currently no, you have to select one sheet. What will be your use-case ? Same data-structure in multiple sheets ? Or retrieving a list with sheet's content ?

Victor

Alik-V commented 2 years ago

Hey Victor, for the current use case the data structure would be identical in each sheet, however, I can envision some use-cases where it would be different. I think in my ideal world, it would write all sheets into a list of dataframes and allow me to do whatever post-processing I need to do afterwards myself. This is how I do it at the moment anyway, but would love to use it in combination with the pretty modal interface of datamods 👍 On the simplest level, something like this:

upload_sheet_data <- function(datapath) {
  # Names of the sheets present in the upload file
  sheet_names <- readxl::excel_sheets(path = datapath)
  # Empty list that will have dataframes appended to it
  upload_list <- list()
  # Loop for each sheet
  for (sheet in sheet_names) {
    # Read the sheet
    data <- readxl::read_xlsx(datapath, sheet = sheet)
    # Bind the data from the sheet to the list
    upload_list[[sheet]] <- data 
  }
  return(upload_list)
}