使用ReporteRs软件包使用R Shiny生成幻灯片



我有一个R闪亮的代码,它可以制作各种报告、单词云、情绪分析和其他各种东西。现在,我希望通过点击一个按钮,所有这些生成的报告都可以在一次拍摄中下载并附加到ppt中。因此,例如,它应该看起来像:

幻灯片1:Word云

幻灯片2:情绪分析

幻灯片3:报告1。。。等等

到目前为止,我可以单独下载所有这些报告,即我在Shiny UI中有不同的选项卡,对于每个报告,我都会转到它并单击"下载",它会被downloadHandler下载。

此外,只需单击一下,我就可以在一个pdf中下载所有这些报告,即在一个页面中我有报告1等等。

到目前为止,我已经到达以下位置:

    #downloadReport is my action button
    #on click of this button I am expecting the ppt. to be downloaded
    observeEvent(input$downloadReport, {
    # Create a PowerPoint document
    doc = pptx( )
    # Slide 1 : Title slide
    #+++++++++++++++++++++++
    doc <- addSlide(doc, "Title Slide")
    doc <- addTitle(doc,"Create a PowerPoint document from R software")
    doc <- addSubtitle(doc, "R and ReporteRs package")

   # Slide 2 : Add Word Cloud
    #+++++++++++++++++++++++
    doc <- addSlide(doc, "Title and Content")
    doc <- addTitle(doc, "Bar Plot")
    newData=rawInputData(); # Function which captures data (.csv file) when I have input it through R shiny
    words_list = strsplit(as.character(newData$CONTENT), " ") #CONTENT is the column which contains the test data
    words_per_tweet = sapply(words_list, length)
    pptwordcloud<-barplot(table(words_per_tweet), border=NA,main="Distribution of words per tweet", cex.main=1,col="darkcyan")
   #pptwordcloud<-barplot(table(words_per_tweet), col="darkcyan")
    doc <- addPlot(doc, fun= print, x = pptwordcloud,vector.graphic =FALSE ) 
    writeDoc(doc,'file1.pptx')
  })

ppt。正在生成,但我无法通过使用vector.graphic =FALSE作为选项在其中看到条形图。如果我删除这个,我得到这个错误

警告:观察器中出现未处理的错误:javax.xml.bind.UnmarshalException-具有链接的异常:[org.xml.sax.SAXParseException:文档中根元素前面的标记必须格式正确。]observeEvent(输入$downloadReport)

有人能指出我的错误吗。

让我们尝试重现=)

1) 我没有你的数据,所以我使用iris,并选择用于table 选择第二列的输入

UI

library(shiny)

shinyUI(
  # Use a fluid Bootstrap layout
  fluidPage(    
    selectInput("sel",label = "col",choices = colnames(iris)[2:ncol(iris)]),
    downloadButton('downloadData', 'Download')
  )
)

服务器

library(shiny)
library(DT)
library(ReporteRs)
shinyServer(function(input, output,session) {
  output$downloadData <- downloadHandler(
      filename = "file.pptx",
      content = function(file) {
        doc = pptx( )
        # Slide 1 : Title slide
        #+++++++++++++++++++++++
        doc <- addSlide(doc, "Title Slide")
        doc <- addTitle(doc,"Create a PowerPoint document from R software")
        doc <- addSubtitle(doc, "R and ReporteRs package")

        # Slide 2 : Add Word Cloud
        #+++++++++++++++++++++++
        doc <- addSlide(doc, "Title and Content")
        doc <- addTitle(doc, "Bar Plot")
        #newData=rawInputData(); # Function which captures data (.csv file) when I have input it through R shiny
        #words_list = strsplit(as.character(newData$CONTENT), " ") #CONTENT is the column which contains the test data
        #words_per_tweet = sapply(words_list, length)
        words_per_tweet=iris
        pptwordcloud<-function(){
          barplot(table(words_per_tweet[,c("Sepal.Length",input$sel)]), border=NA,main="Distribution of words per tweet", cex.main=1,col="darkcyan")
        }#pptwordcloud<-barplot(table(words_per_tweet), col="darkcyan")
        doc <- addPlot(doc, fun= pptwordcloud,vector.graphic =FALSE ) 
        writeDoc(doc,file)
       }
     )
  })

相关内容

  • 没有找到相关文章

最新更新