I am trying to use a download button in the input column of a flexdashboard to download a collection of charts rendered as *.pdf. The entire dashboard works just fine, and the download button renders properly; however, when I click the download button, the file that does get downloaded does not contain the intended charts. The warning I get from my Mac when it tries to open the file is that the file might be damaged or that it's a form that Preview (or Acrobat) doesn't recognize. The following is a highly redacted form of my code that contains the problematic sections. Any guidance on how to get charts to download in a flexdashboard as charts download in Shiny?
Thanks in advance,
RB
---
title: "My Model"
runtime: shiny
output:
flexdashboard::flex_dashboard:
theme: cerulean
vertical_layout: scroll
orientation: rows
---
```{r global, include=FALSE}
library(shiny)
library(shinyBS)
library(shinyWidgets)
library(flexdashboard)
library(tidyverse)
library(readxl)
library(knitr)
```
```{r Inputs}
downloadButton("downlaodReport","Price Comparision Report")
downloadHandler(filename = function() {
filename = paste0("Analysis-", Sys.Date(), ".pdf")
},
content = function(file) {
pdf(file, width = 8.5, height = 6.14)
renderPrint({ output$gg.prob.win.price() })
dev.off()
}
)
```
```{r priceProbWinChart}
renderPlot({
gg.prob.win.price <- {## ggplot code goes here ##}
plot(gg.prob.win.price)
})
```