[英]Connect R and Excel
我想連接 Excel 和 R。我在 R 中做了一個可視化,數據取自 excel。 現在我想做的是,輸入和輸出應該在 excel 本身上。 因此,對於輸入,excel 上的屏幕將是一個表格,用戶必須填寫表格。 該表將是 R 中可視化的輸入,因此該表將在 R 中讀取,輸出將顯示在 excel 中。 現在我知道如何將 R 的輸出顯示為 excel。 但我不知道如何在excel中做這個輸入屏幕。
我的目標是用戶不必打開 R,因為他們不會知道。 我希望 R 在后台。 我知道 RExcel 但它仍然必須給出一些命令。 是否可以這樣做。
如果你們中的任何人可以提供幫助,那就太好了。 謝謝
這些選項之一應該可以幫助您前進。
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)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.