R Shiny导出logging到由用户命名的Excel工作簿

我试图编写一个Shiny应用程序只是为了练习应用程序需要一张Excel表格,从Excel工作表抓取一个ID号码,并对数据库运行这些ID从数据库返回一些额外的细节

就这个例子而言,我已经导入了数据并计算了数据集中的行数。 然后,我将这个数据集传递给函数get_DW ,它将返回一个dataframe,我想要计算返回的dataframe中的logging数。 当用户按下Gobutton时,会发生此步骤

当我运行我的shiny的应用程序,数据导入和logging的数量进行计数。 我也设法让它从数据库返回logging并计算这些logging。

我无法导出使用output$downloadData ,没有任何反应。 我按下button获取对话框保存,但是当我input文件名,然后按保存没有得到保存到文件夹

任何人都可以看到在代码中我可能会出错的地方。 我已经看到了这个问题从XLConnect R下载Excel文件Shiny,但它不使用我想要的库和我不是很清楚的解释给出

我更新了下面的代码来使用虹膜数据集。 它有点乱,但它复制了节省的缺乏

服务器代码

 # Server Code server <- shinyServer(function(input, output) { # Create a reactive expression which will grab the data # We pass that to the outputs reactive element to the outputs data <- reactive({ iris }) # Return the number of records output$Inputnum <- renderText({ paste(nrow(data()), "records to be checked") }) # Data returned by Database en_data <- eventReactive(input$go, { get_DW(data()) }) # Return the number of records output$Outputnum <- renderText({ paste(nrow(en_data()), "records matched") }) output$downloadData<- downloadHandler( filename = function() { "name.xlsx" }, content = function(file) { tempFile <- tempfile(fileext = ".xlsx") write.xlsx(en_data(), tempFile) file.rename(tempFile, file) }) }) 

UI代码

 shinyUI( fluidPage( titlePanel("POC"), sidebarLayout( sidebarPanel( fileInput(inputId = 'file1',label = 'Choose An Excel File', accept=c('.xlxs')), radioButtons(inputId = "radio", label = "Search By:", choices = list("option 1" = 1, "option 2" = 2, "option 3" = 3), selected = 1), hr(), fluidRow(column(1, actionButton("go", "Get Records")), column(2,offset = 2, downloadButton('downloadData', 'Download')), br() )), mainPanel( verbatimTextOutput("Inputnum"), br(), verbatimTextOutput("Outputnum") ) ) )) 

全球R文件

 #in global.R options (scipen=FALSE,stringsAsFactors=FALSE) library(xlsx) library(RODBC) library(dplyr) get_DW <- function (mydf) { mydf } 

几周前我遇到了同样的问题。 尝试在外部而不是本地运行您的应用程序。 这对我使用你的示例代码。

在这里输入图像说明