Reputation: 1
I'm new at RStudio's Shiny. I would like to upload a file and display it's content. So far I have the code provided here http://shiny.rstudio.com/gallery/file-upload-widget.html How do I save the uploaded file's content into a variable and then display it?
Upvotes: 0
Views: 2943
Reputation: 26313
Something like this would get you started. It's obviously very rough code (it doesn't even sanitize the input, and it has an error shown to the user until a file is selected), but it'll give you an idea of how to upload, read, and show a file.
library(shiny)
ui <- fluidPage(
fileInput("file", "Select a file"),
verbatimTextOutput("text")
)
server <- function(input, output, session) {
output$text <- renderText({
filePath <- input$file$datapath
fileText <- paste(readLines(filePath), collapse = "\n")
fileText
})
}
shinyApp(ui = ui, server = server)
Upvotes: 3