Tag: shiny的

下载多张作为数据框的xls文件Shiny R

我正在使用R包Shiny来开发我自己的Web应用程序。 我有一个下载button,允许我将数据导出到Excel文件。 在excel文件中,有4张纸,每张纸上都有一个数据框。 例如,在sheet1中有dataTab1,在sheet2中有dataTab2,在sheet3中有dataTab3,在sheet4中有dataTab4。 为此,我正在使用函数downloadHeader()在shiny的server.R中。 我已经使用了两种方法来做到这一点。 方法1:使用R包xlsx output$downloadTab <- downloadHandler( filename = "dataxls.xlsx", content = function(file) { #creation of the workbook dataxls=createWorkbook(file) #creation of the sheets dataTabs1=createSheet(wb=dataxls,sheetName="Compartiments-simulation_sans_changement") dataTabs2=createSheet(wb=dataxls,sheetName="Esperance-simulation_sans_changement") dataTabs3=createSheet(wb=dataxls,sheetName="Compartiments-simulation_avec_changement") dataTabs4=createSheet(wb=dataxls,sheetName="Esperance-simulation_avec_changement") #add the dataframes to the sheets writeWorksheet(dataxls, dataTab1, sheet = "Compartiments-simulation_sans_changement") writeWorksheet(dataxls, dataTab2, sheet = "Esperance-simulation_sans_changement") writeWorksheet(dataxls, dataTab3, sheet = "Compartiments-simulation_avec_changement") writeWorksheet(dataxls, dataTab4, sheet = […]

在Shiny R App中使用read.xlsx

我正在尝试加载一个Excel文件并显示摘要。 该文件正在加载没有任何错误,但没有显示任何东西。 这是我的代码 ui.R library(shiny) shinyUI(pageWithSidebar( headerPanel("Analysis"), sidebarPanel(wellPanel(fileInput('file1', 'Choose XLSX File', accept=c('sheetName', 'header'), multiple=FALSE))), mainPanel( tabsetPanel( tabPanel("Tab1",h4("Summary"), htmlOutput("summary")) ))) server.R library(shiny) shinyServer(function(input, output) { dataset = reactive({ infile = input$file1 if (is.null(infile)) return(NULL) infile_read = read.xlsx(infile$datapath, 1) return(infile_read) }) output$summary <- renderPrint({ summary = summary(dataset()) return(summary) }) outputOptions(output, "summary", suspendWhenHidden = FALSE) })

如何使用R-shiny和shinyFiles指定文件和path来保存文件?

我正在与R(shiny),并希望将数据框保存为Excel文件。 为此,我使用“shinyFiles”包,以便用户可以指定excel文件的存储位置: server.R库(shiny)库(shinyFiles) shinyServer(function(input, output, session) { ## ShinyFiles : get the user favorite directory volumes=c(home = '~/'), shinyDirChoose(input, 'dir', roots=volumes, filetypes = c('','xlsx')), output$dir.res <- renderPrint({parseDirPath(volumes, input$dir)}), ## Button to save the file observeEvent(input$button.save, { ## A standard file name A <- "name" B <- "family if( input$text == "File name…" ) outFile <- […]

检查R中是否存在数据表

我有一个shiny的应用程序,用户可以上传一个文件。 根据这个文件是否有1或2个数据表,function应该是不同的。 我使用read.xlsx导入数据表,其中data_in是path: data <-read.xlsx(data_in,1,1,colNames=TRUE) 所以这是文件的第一张表格。 第二张纸可以用相同的方式input。 但是如果它没有第二张纸,我希望它通过粘贴警告或以不同方式继续处理。 那么,如何确定数据文件中是否存在第二个工作表? 感谢你的帮助! 谢谢

使用R Shiny从XLConnect下载Excel文件

有没有人尝试使用R Shiny下载处理程序下载新创build的XLConnect Excel文件? 在ui.R有一个不起眼的线: downloadButton('downloadData', 'Download') 在server.R中有处理程序: output$downloadData <- downloadHandler( filename = function() { "output.xlsx" }, content = function(file){ wb <- loadWorkbook(file, create = TRUE) createSheet(wb, name = "Sheet1") writeWorksheet(wb, c(1:3), sheet = "Sheet1") # writes numbers 1:3 in file saveWorkbook(wb) } ) 我没有问题下载一个.csv和没有问题创build与XLConnect的Excel文件。 但是,当我运行上面的代码时,我的Chrome浏览器中出现以下错误: IllegalArgumentException(Java):不支持文件扩展名“file1b683b9323bc”! 只允许* .xls和* .xlsx! 据我所见,XLConnect不能写入临时文件。 有没有人有解决scheme或解决方法? 一种select是将文件保存在特定位置,然后创build指向它的下载链接。 但是,由于多个用户会导致havok,所以这不是很有光泽。 非常感谢 马库斯