'Shiny readRDS fail to work with rds object containing a list of data frame
I was trying to develop a shiny app that allows users to upload an rds file and do clustering analysis. The rds object contains a list of dataframe. Yet somehow the readRDS function didn't work with my rds object.
Here is part of my code
library(shiny)
ui <- fluidPage(
# App title ----
titlePanel("test"),
sidebarLayout(
wellPanel(
fileInput(inputId = 'upload',NULL,
label= 'Upload an rds file',
buttonLabel = 'Choose File',multiple=FALSE,
placeholder = 'No file selected',
accept = '.rds'),
mainPanel(
tableOutput('content')
)
)
)
)
server <- function(input,output) {
my_dtw <-reactive({
file <-input$upload
ext <- tools::file_ext(file$datapath)
req(file)
validate(need(ext == "rds", "Please upload a rds file"))
df <-readRDS(file$datapath)
return(df)
})
output$content <- renderTable(my_dtw()[1:3,])
}
shinyApp(ui = ui, server = server)
And here is my rds object:https://github.com/JuanXie19/data/blob/main/Mice.sub2.trajectory.rds
Many thanks in advance!!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
