在一个闪亮的应用程序中的"read_excel"

pol*_*lTo 14 r xlsx shiny

我有一个使用read.xlsx包中的功能的Shiny应用程序xlsx.所有工作正常,但我想更改为read_excelreadxl,希望这将是更快,能够应付大容量文件.

你的部分:

fileInput("inputFile","Upload file...")
Run Code Online (Sandbox Code Playgroud)

服务器部分:

  data <- reactive({
    inFile <- input$inputFile
    if (is.null(inFile)) { return(NULL) }    
    dataFile <- read_excel(inFile$datapath,sheet=1)
    return(dataFile)
  })
Run Code Online (Sandbox Code Playgroud)

我收到"未知格式"错误.

inFile $ datapath是"
/tmp/.../60974676c7287e913d1c0dc5/0"inFile $ type是"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"

问题1:有没有办法告诉read_excel它是xlsx类型的文件?
问题2:是否可以控制上传文件的存储位置?

cde*_*man 18

这是readxl包的一个开放性问题.提供的当前解决方法是复制文件数据路径并追加.xlsx.这是我的机器上的一个工作示例,仅限于.xlsx编辑使用的文件file.rename而不是file.copy.

library(shiny)
library(readxl)

runApp(
    list(
        ui = fluidPage(
            titlePanel("Use readxl"),
            sidebarLayout(
                sidebarPanel(
                    fileInput('file1', 'Choose xlsx file',
                              accept = c(".xlsx")
                              )
                    ),
                mainPanel(
                    tableOutput('contents'))
                )
            ),
        server = function(input, output){
            output$contents <- renderTable({
                inFile <- input$file1

                if(is.null(inFile))
                    return(NULL)
                file.rename(inFile$datapath,
                          paste(inFile$datapath, ".xlsx", sep=""))
                read_excel(paste(inFile$datapath, ".xlsx", sep=""), 1)
            })
        }
        )
    )
Run Code Online (Sandbox Code Playgroud)

编辑 请注意,使用它的1.1.0版本readxl不再需要重命名文件.以下工作对我来说没有问题.

library(shiny)
library(readxl)

runApp(
  list(
    ui = fluidPage(
      titlePanel("Use readxl"),
      sidebarLayout(
        sidebarPanel(
          fileInput('file1', 'Choose xlsx file',
                    accept = c(".xlsx")
          )
        ),
        mainPanel(
          tableOutput('contents'))
      )
    ),
    server = function(input, output){
      output$contents <- renderTable({

        req(input$file1)

        inFile <- input$file1

        read_excel(inFile$datapath, 1)
      })
    }
  )
)
Run Code Online (Sandbox Code Playgroud)