[英]Connect R and Excel
I want to connect Excel and R. I have done a visualisation in R and the data was taken from excel.我想连接 Excel 和 R。我在 R 中做了一个可视化,数据取自 excel。 Now what i want to do is, the input and output should be on excel itself.现在我想做的是,输入和输出应该在 excel 本身上。 So for the input, the screen on the excel will be a table and the user has to fill the table.因此,对于输入,excel 上的屏幕将是一个表格,用户必须填写表格。 The table will be the input for the visualisation in R, so then the table will be read in R and the output will be displayed in excel.该表将是 R 中可视化的输入,因此该表将在 R 中读取,输出将显示在 excel 中。 Now I know how to show the output from R to excel.现在我知道如何将 R 的输出显示为 excel。 But I don't know how to do this input screen in excel.但我不知道如何在excel中做这个输入屏幕。
My goal is the user doesn't have to open R as they won't know.我的目标是用户不必打开 R,因为他们不会知道。 I want R to be in background.我希望 R 在后台。 I know RExcel but it still has to give some commands.我知道 RExcel 但它仍然必须给出一些命令。 Is it possible to do it this way.是否可以这样做。
This is how i want it to be这就是我想要的样子
It will be great, if any of you can help.如果你们中的任何人可以提供帮助,那就太好了。 Thanks谢谢
One of these options should get you going.这些选项之一应该可以帮助您前进。
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)
})
}
)
)
OR或者
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)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.