[英]Upload file and display content in R Shiny
I'm new at RStudio's Shiny. 我是RStudio的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? 到目前为止,我已经在此处提供了以下代码: http://shiny.rstudio.com/gallery/file-upload-widget.html如何将上传文件的内容保存到变量中,然后显示出来?
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)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.