0

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. Commented 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. Commented Sep 29, 2016 at 4:35

1 Answer 1

3

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) 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.