首页 > 解决方案 > 如何通过 Shiny 上传 www 文件夹中的文件

问题描述

我希望我的文件上传到 Shiny 的 www 文件夹中。我正在使用此代码上传,但它没有上传 www 文件夹中的文件。有谁知道我该怎么做?我的操作系统是 Windows。我正在使用这段代码:

这是“ui.R”:

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'),
                   ',')
    ),
    mainPanel(
      tableOutput('contents')
    )
  )
)

这是“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 = 9*1024^2)

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, header = input$header,
             sep = input$sep, quote = input$quote)
  })
}

标签: rshinyshiny-server

解决方案


推荐阅读