【问题标题】:Connect R and Excel连接 R 和 Excel
【发布时间】:2019-07-24 09:45:30
【问题描述】:

我想连接 Excel 和 R。我在 R 中做了一个可视化,数据取自 excel。现在我想做的是,输入和输出应该在excel本身上。因此,对于输入,excel 上的屏幕将是一个表格,用户必须填写表格。该表将是 R 中可视化的输入,因此该表将在 R 中读取,输出将显示在 excel 中。现在我知道如何将 R 的输出显示到 excel 中。但我不知道如何在excel中做这个输入屏幕。

我的目标是用户不必打开 R,因为他们不会知道。我希望 R 在后台。我知道 RExcel,但它仍然需要给出一些命令。这种方式可以吗。

This is how i want it to be

如果你们中的任何人能提供帮助,那就太好了。谢谢

【问题讨论】:

  • 可能是try shiny?输入可以是 CSV/Excel,然后使用下载按钮在应用程序中绘图?甚至可以导出带有绘图的 Excel 工作表。
  • 好的。会尝试的。谢谢!
  • 但是我可以做我想做的事吗?

标签: r excel openoffice-calc


【解决方案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)
            })
        }
        )
    )

library(shiny)
library(readxl)

ui <- fluidPage(
  fileInput('file1', 'Insert File', accept = c(".xlsx")),
  textInput('file1sheet','Name of Sheet (Case-Sensitive)'),
  tableOutput("value")
)

server <- function(input, output) {

  sheets_name <- reactive({
    if (!is.null(input$file1)) {
      return(excel_sheets(path = input$file1$datapath))  
    } else {
      return(NULL)
    }
  })

  output$value <- renderTable({
    if (!is.null(input$file1) && 
        (input$file1sheet %in% sheets_name())) {
      return(read_excel(input$file1$datapath, 
                        sheet = input$file1sheet))
    } else {
      return(NULL)
    }
  })
}

shinyApp(ui, server)

【讨论】:

    猜你喜欢
    • 2013-10-12
    • 1970-01-01
    • 2012-04-15
    • 1970-01-01
    • 1970-01-01
    • 2016-06-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多