Spaces:
Sleeping
Sleeping
| library(shiny) | |
| library(data.table) | |
| library(dplyr) | |
| library(shinycssloaders) | |
| options(shiny.maxRequestSize = 100000 * 1024^2) | |
| ui <- fluidPage( | |
| titlePanel("CSV File Combiner"), | |
| sidebarLayout( | |
| sidebarPanel( | |
| fileInput("file_input", "Choose CSV Files", multiple = TRUE, accept = c("text/csv", ".csv")), | |
| actionButton("combine_button", "Combine Files"), | |
| br(), | |
| br(), | |
| downloadButton("download_data", "Download Combined CSV") | |
| ), | |
| mainPanel( | |
| withSpinner(tableOutput("preview_table")) | |
| ) | |
| ) | |
| ) | |
| server <- function(input, output, session) { | |
| combined_data <- reactiveVal(NULL) | |
| observeEvent(input$combine_button, { | |
| req(input$file_input) | |
| withProgress(message = 'Combining files', value = 0, { | |
| combined <- data.frame() | |
| for (i in 1:nrow(input$file_input)) { | |
| file <- input$file_input$datapath[i] | |
| data <- fread(file) | |
| combined <- rbind(combined, data) | |
| incProgress(1/nrow(input$file_input), detail = paste("Processing file", i)) | |
| } | |
| combined_data(combined) | |
| }) | |
| }) | |
| output$preview_table <- renderTable({ | |
| req(combined_data()) | |
| head(combined_data(), 10) | |
| }) | |
| output$download_data <- downloadHandler( | |
| filename = function() { | |
| paste("combined_data_", Sys.Date(), ".csv", sep = "") | |
| }, | |
| content = function(file) { | |
| write.csv(combined_data(), file, row.names = FALSE) | |
| } | |
| ) | |
| } | |
| shinyApp(ui = ui, server = server) |