首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在RShiny中上传excel文件

问在RShiny中上传excel文件
EN

Stack Overflow用户
提问于 2020-04-16 13:55:10
回答 1查看 241关注 0票数 0

我正在尝试上传excel文件与多张表在R使用闪光库。此外,我必须上传多个excel文件。有谁能告诉我怎么解决这个问题吗?

EN

回答 1

Stack Overflow用户

发布于 2020-04-17 08:18:34

这是一个简单的实用工具,可以打开Excel工作簿并从下拉列表中加载单个工作表。然后它会显示该表。希望这篇文章能帮你入门。

代码语言:javascript
复制
# Utility to read any Excel workbook and display a worksheet

library("shiny")
library("gdata")
library("tableHTML")

# Define UI for application that draws a histogram
ui <- fluidPage(

  # Application title
  titlePanel("Utility to read and display an Excel spreadsheet"),
  sidebarLayout(

    sidebarPanel (label="Data Source",
                  # Spreadsheet name and sheet name 
                  fileInput("spreadsheetName", "Spreadsheet Name",accept = c(".xlsx")),
                  selectInput(inputId = "worksheet", label="Worksheet Name",choices=''),
                  actionButton(inputId = "getData",label="Get Data")),

    mainPanel (
     tableHTML_output("table1Data")
    )
  )
)

# Define server logic required to draw a histogram
server <- function(input, output, session) {
  # Read the data from the spreadsheet
  observe({
    # Get the annual data
    # Check if file is there... if not, exit and wait for it again
    inFile <- input$spreadsheetName
    if (is.null(inFile)) {
      return (NULL)
    }
    else {
      # Set up the selection for the worksheet names within the selected file
      filePath <<- inFile$datapath
      selectionWorksheet <- sort(unique(sheetNames (inFile$datapath)))
      updateSelectInput(session, "worksheet", choices = selectionWorksheet)
    }
  })

  # Get data
  observeEvent(input$getData, {

    # Get the data from the spreadsheet worksheets
    worksheetData <- read.xls (filePath, sheet=input$worksheet, header=TRUE, stringsAsFactors = FALSE)

    # Print the Annual table
    output$table1Data <- renderTable ({
      worksheetData
    # End of main program
    })
  })
}

# Run the application 
shinyApp(ui = ui, server = server)
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61243586

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档