我有一个显示大约 15 个图表的闪亮仪表板应用程序。我正在使用 ReporteRs 允许用户下载包含图表的 powerpoint 报告;每张幻灯片一个。我现在为每个图表添加了一些复选框,并且想知道如何使报告生成动态化,因此如果用户选中一个图表,则只生成一张幻灯片;如果他们选择两个图表,则制作两张幻灯片,依此类推。
这是一个简单的例子。我有两张图表。如果我在下载选项卡上取消选择一张,我如何告诉记者我只想要一张带有所选图表的幻灯片?如果我同时检查两者,ReporteRs 会生成两张幻灯片。我的想法是,如果我能解决这个问题,我只需扩大到所需的 15 个。
谢谢,安德鲁
library(shiny)
library(ReporteRs)
# Define UI for application that draws a histogram
#ui <- fluidPage(
ui <- fluidPage(
titlePanel("Powerpoint Report"),
mainPanel(
tabsetPanel(
tabPanel(
title = "Plots",
solidHeader = FALSE,
HTML("<br /><br /><br />"),
fluidRow(
column(width = 6,
plotOutput("barPlot1")
),
column(width = 6,
plotOutput("barPlot2")
)
)
),
tabPanel(
title = "Download",
solidHeader = FALSE,
HTML("<br /><br /><br />"),
checkboxGroupInput("down", "Select Charts",
choices = c("Cars Plot" = 1, "Iris Plot" = 2),
selected = list(1, 2)),
HTML("<br /><br />"),
downloadButton("download", "Download Powerpoint Report")
)
)
)
)
server <- function(input, output) {
car <- function(){plot(cars$speed, cars$dist)}
output$barPlot1 <- renderPlot(
car()
)
iri <- function(){plot(iris$Sepal.Length, iris$Petal.Length)}
output$barPlot2 <- renderPlot(
iri()
)
output$download <- downloadHandler(
file = "charts.pptx",
content = function(file){
doc = pptx( )
doc <- addSlide(doc, "Title Slide")
doc <- addTitle(doc,"How many Charts?")
doc <- addSlide(doc, "Two Content")
doc <- addTitle(doc,"Car Charts?")
doc <- addPlot(doc, fun = function() car())
doc <- addSlide(doc, "Two Content")
doc <- addTitle(doc, "Iris Plot")
doc <- addPlot(doc, fun = function() iri())
writeDoc(doc, file)
}
)
}
# Run the application
shinyApp(ui = ui, server = server)