我正在尝试创建一个简单的程序来上传和显示Shiny中的.csv文件的内容 . 我从闪亮的网站上复制粘贴了文件上传示例,但它没有用 . 输出表只显示“X.object.Object” . 我收到警告:

Warning in read.table(file = file, header = header, sep = sep, quote = quote,  :
  incomplete final line found by readTableHeader on     '/var/folders/2d/2vmslzld48xf_y40rjg3sry00000gp/T//RtmpRLx4Va/aa2cf08f688d80f5d1fd5209/0'
Warning in matrix(align.tmp[(2 - pos):(ncol(x) + 1)], nrow = nrow(x), ncol = ncol(x) +  :
  data length exceeds size of matrix

我做了一些额外的元素来显示Shiny文件上传输入中的文件对象,以及file.info在它给出的文件路径上的结果 . Shiny输入对象看起来很好(正确检测文件类型和大小),但file.info表示它应该是几kb时只有15个字节长 . 使用readChar将文件的内容作为简单字符串获取也不起作用 . 从控制台读取read.csv或readChar文件可以正常工作 . 我认为它在某种程度上不会在上传时正确保存文件 . 我怎么检查这个?

ui.R:

shinyUI(fluidPage(
  titlePanel("Uploading Files"),
  sidebarLayout(
    sidebarPanel(
      fileInput('file1', 'Choose file to upload',
                accept = c(
                  'text/csv',
                  'text/comma-separated-values',
                  'text/tab-separated-values',
                  'text/plain',
                  '.csv',
                  '.tsv'
                )
      ),
      tags$hr(),
      checkboxInput('header', 'Header', TRUE),
      radioButtons('sep', 'Separator',
                   c(Comma=',',
                     Semicolon=';',
                     Tab='\t'),
                   ','),
      radioButtons('quote', 'Quote',
                   c(None='',
                 'Double Quote'='"',
                     'Single Quote'="'"),
                   '"')
    ),
    mainPanel(
      tableOutput('contents'),
      tableOutput('stuff1'),
      tableOutput('stuff2'),
      textOutput('moreStuff')
    )
  )
))

server.R

# By default, the file size limit is 5MB. It can be changed by
# setting this option. Here we'll raise limit to 9MB.
options(shiny.maxRequestSize = 10*1024^2)

shinyServer(function(input, output) {
  output$contents <- renderTable({
    # input$file1 will be NULL initially. After the user selects
    # and uploads a file, it will be a data frame with 'name',
    # 'size', 'type', and 'datapath' columns. The 'datapath'
    # column will contain the local filenames where the data can
    # be found.

    inFile <- input$file1

    if (is.null(inFile))
      return(NULL)

    read.csv(inFile$datapath)
  })

  output$stuff1 <- renderTable({
    inFile <- input$file1

    if (is.null(inFile))
      return(NULL)

    file.info(inFile$datapath)[c("size", "isdir", "mode", "uid", "gid", "uname", "grname")]
  })

  output$stuff2 <- renderTable({
    inFile <- input$file1

    if (is.null(inFile))
      return(NULL)

    as.data.frame(inFile)
  })

  output$moreStuff <- renderText({
    inFile <- input$file1

    if (is.null(inFile))
      return(NULL)

    readChar(inFile$datapath, inFile$size)
  })
})