Hi guys,
I am hoping that someone will be able to help me to work with input files constructed into an S4 object within a shiny application.
The default behaviour in R is as follows:
library(flowCore)
fs <- read.flowSet(files = ("pathtomultiplefiles.fcs"))
# fs object is a set of files contained in an S4 object - data from individual files can be accessed by "[[" method
fs[[1]]
In the shiny application I have used fileInput for the user to upload files and constructed the reactive expression (called data()) containing the fs object:
ui <- fluidPage(
titlePanel("Upload .fcs files:"),
sidebarLayout(
sidebarPanel(
fileInput(inputId = "Files",
label = "Select Samples",
multiple = TRUE,
accept = ".fcs")
),
mainPanel(
textOutput("class"),
textOutput("names"),
)
)
)
server <- function(input, output) {
data <- reactive({
fs <- read.flowSet(files = input$Files$datapath)
})
output$class <- renderText({
req(input$Files)
print(class(data()))
})
output$names <- renderText({
req(input$Files)
print(sampleNames(data())) # Print the filenames
})
}
shinyApp(ui = ui, server = server)
The files have been successfully added as the class and names outputs yield the correct results.
The problem is how do you extract elements from data() (e.g. data()[[1]])? Is this possible or should the data be handled in a different way?
Thanks for your help!