I have a shiny application which reads in multiple csv/txt files, combines them into a list and reactively outputs the data table of the selected file. See below.
library(DT)
library(shiny)
library(data.table)
ui <- fluidPage(sidebarLayout(
sidebarPanel(
fileInput(
"files",
"Choose File",
multiple = TRUE,
accept = c(
"text/csv",
"text/comma-separated-values,text/plain",
".dp_txt",
".is_txt"
)
),
selectizeInput(
inputId = "selected_table",
label = "Table Selection",
choices = NULL,
selected = NULL,
multiple = FALSE
)
),
mainPanel(DTOutput("table"))
))
server <- function(input, output, session) {
observeEvent(input$files, {
freezeReactiveValue(input, "selected_table")
updateSelectizeInput(session,
inputId = "selected_table",
choices = input$files$name,
server = TRUE)
})
table_list <- reactive({
req(input$files)
setNames(lapply(input$files$datapath, function(x) {
fread(x)
}),
input$files$name)
})
output$table <- renderDT({
req(table_list(), input$selected_table)
table_list()[[input$selected_table]]
}, server = FALSE)
}
shinyApp(ui, server)
However, I want to take the raw data-frames within the list through ~20 transformations (the same transformations for each data frame) prior to outputting the selected data table. I would like to do this for all of the data tables not just one I am outputting as I plan to make a summary tab. I will also need to do things like make new lists from the original list during this data processing.
As a basic example lets say I want to start by removing the first two rows from every data-frame within my list prior to outputting the selected table using something like lapply(list_of_df, function(x) as.data.frame(x[-c(1,2),])). How would I go about doing this with the shiny app example given above?