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?
2
- There are lots of resources provided by RStudio, check them out for tips: file upload and display.desc– desc2016-09-29 01:26:30 +00:00Commented Sep 29, 2016 at 1:26
- I'm aware of those. I meant i would like to upload for instance somerandomfile.txt and then display all it's content on the page. Let's say somerandomfile.txt has the content: Hello world. When i upload this .txt i want Hello world to show up under it.user3708214– user37082142016-09-29 04:35:12 +00:00Commented Sep 29, 2016 at 4:35
Add a comment |
1 Answer
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)