gpt4 book ai didi

r - 使用 ReporteRs 包通过 R Shiny 生成 powerpoint 幻灯片

转载 作者:行者123 更新时间:2023-12-02 17:44:49 25 4
gpt4 key购买 nike

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

幻灯片 1:词云

幻灯片 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 作为选项,我无法在其中看到条形图。如果我删除它,我会收到此错误

Warning: Unhandled error in observer: javax.xml.bind.UnmarshalException - with linked exception: [org.xml.sax.SAXParseException: The markup in the document preceding the root element must be well-formed.] observeEvent(input$downloadReport)

有人可以指出我的错误吗?

最佳答案

让我们尝试重现=)

1)我没有您的数据,因此我使用iris并选择用于选择第二列的输入

用户界面

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)
}
)
})

关于r - 使用 ReporteRs 包通过 R Shiny 生成 powerpoint 幻灯片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36334728/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com