【问题标题】:How to open .XLS files using shinyApp如何使用 shinyApp 打开 .XLS 文件
【发布时间】:2018-04-17 07:39:15
【问题描述】:

我有 18 个 (.XLS) 文件,我想使用 Shiny 打开和阅读它们。我不确定问题出在哪里。更改后,我能够使用相同的代码打开(.xlsx)文件 accept = c(".xlsx")

install.packages("readxl")
library(shiny)
library(readxl)

runApp(
  list(
    ui = fluidPage(
      titlePanel("Use readxls"),
      sidebarLayout(
        sidebarPanel(
          fileInput('file1', 'Choose XLS file',
                    accept = c(".XLS")
          )
        ),
        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, ".XLS", sep=""))
        read_excel(paste(inFile$datapath, ".XLS", sep=""), 1)
      })
    }
  )
)

不是excel文件 警告:read_fun 中的错误:无法打开 /var/folders/df/5cr7h6td3432hn68rplrj6lm0000gn/T//RtmpohK8Zl/2f5ccd8bfa3742ad3ec38aef/0.XLS.XLS

1- 为什么不是excel文件?我似乎无法识别此路径或文件夹。文件和文件夹的名称与我在此错误中看到的不同

2- 有没有办法在一个目录中打开多个文件?

【问题讨论】:

  • 您好像粘贴了两次“.xls”,所以“0.xls.xls”不是文件。
  • 我试过 read_excel(paste(inFile$datapath, sep=""), 1) 但没有用。
  • 当我将 read_excel 更改为 read.table() 时它工作了

标签: r excel xls shiny


【解决方案1】:

这对我来说很好。

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)
            })
        }
        )
    )

【讨论】:

  • 它适用于 xlsx 文件。但是,通过使用 read.table() 解决了这个问题
猜你喜欢
  • 1970-01-01
  • 2012-02-17
  • 1970-01-01
  • 2020-05-04
  • 1970-01-01
  • 1970-01-01
  • 2019-06-14
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多