Spaces:
Sleeping
Sleeping
Update app.R
Browse files
app.R
CHANGED
|
@@ -1,58 +1,58 @@
|
|
| 1 |
library(shiny)
|
| 2 |
-
library(
|
| 3 |
library(dplyr)
|
| 4 |
-
library(
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
varSelectInput("yvar", "Y variable", df_num, selected = "Bill Depth (mm)"),
|
| 16 |
-
checkboxGroupInput("species", "Filter by species",
|
| 17 |
-
choices = unique(df$Species), selected = unique(df$Species)
|
| 18 |
),
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
),
|
| 24 |
-
plotOutput("scatter")
|
| 25 |
)
|
| 26 |
|
| 27 |
server <- function(input, output, session) {
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
)
|
| 43 |
-
|
| 44 |
-
if (input$show_margins) {
|
| 45 |
-
margin_type <- if (input$by_species) "density" else "histogram"
|
| 46 |
-
p <- p |> ggExtra::ggMarginal(
|
| 47 |
-
type = margin_type, margins = "both",
|
| 48 |
-
size = 8, groupColour = input$by_species, groupFill = input$by_species
|
| 49 |
-
)
|
| 50 |
}
|
| 51 |
-
|
| 52 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
},
|
| 54 |
-
|
|
|
|
|
|
|
| 55 |
)
|
| 56 |
}
|
| 57 |
|
| 58 |
-
shinyApp(ui, server)
|
|
|
|
| 1 |
library(shiny)
|
| 2 |
+
library(data.table)
|
| 3 |
library(dplyr)
|
| 4 |
+
library(shinycssloaders)
|
| 5 |
+
options(shiny.maxRequestSize = 100000 * 1024^2)
|
| 6 |
+
ui <- fluidPage(
|
| 7 |
+
titlePanel("CSV File Combiner"),
|
| 8 |
+
sidebarLayout(
|
| 9 |
+
sidebarPanel(
|
| 10 |
+
fileInput("file_input", "Choose CSV Files", multiple = TRUE, accept = c("text/csv", ".csv")),
|
| 11 |
+
actionButton("combine_button", "Combine Files"),
|
| 12 |
+
br(),
|
| 13 |
+
br(),
|
| 14 |
+
downloadButton("download_data", "Download Combined CSV")
|
|
|
|
|
|
|
|
|
|
| 15 |
),
|
| 16 |
+
mainPanel(
|
| 17 |
+
withSpinner(tableOutput("preview_table"))
|
| 18 |
+
)
|
| 19 |
+
)
|
|
|
|
|
|
|
| 20 |
)
|
| 21 |
|
| 22 |
server <- function(input, output, session) {
|
| 23 |
+
combined_data <- reactiveVal(NULL)
|
| 24 |
+
|
| 25 |
+
observeEvent(input$combine_button, {
|
| 26 |
+
req(input$file_input)
|
| 27 |
+
|
| 28 |
+
withProgress(message = 'Combining files', value = 0, {
|
| 29 |
+
combined <- data.frame()
|
| 30 |
+
|
| 31 |
+
for (i in 1:nrow(input$file_input)) {
|
| 32 |
+
file <- input$file_input$datapath[i]
|
| 33 |
+
data <- fread(file)
|
| 34 |
+
combined <- rbind(combined, data)
|
| 35 |
+
|
| 36 |
+
incProgress(1/nrow(input$file_input), detail = paste("Processing file", i))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
}
|
| 38 |
+
|
| 39 |
+
combined_data(combined)
|
| 40 |
+
})
|
| 41 |
+
})
|
| 42 |
+
|
| 43 |
+
output$preview_table <- renderTable({
|
| 44 |
+
req(combined_data())
|
| 45 |
+
head(combined_data(), 10)
|
| 46 |
+
})
|
| 47 |
+
|
| 48 |
+
output$download_data <- downloadHandler(
|
| 49 |
+
filename = function() {
|
| 50 |
+
paste("combined_data_", Sys.Date(), ".csv", sep = "")
|
| 51 |
},
|
| 52 |
+
content = function(file) {
|
| 53 |
+
write.csv(combined_data(), file, row.names = FALSE)
|
| 54 |
+
}
|
| 55 |
)
|
| 56 |
}
|
| 57 |
|
| 58 |
+
shinyApp(ui = ui, server = server)
|