首页 > 解决方案 > 在 flexdashboard 中下载图表

问题描述

我正在尝试使用 flex 仪表板的输入列中的下载按钮来下载呈现为 *.pdf 的图表集合。整个仪表板工作正常,下载按钮正常呈现;但是,当我单击下载按钮时,下载的文件不包含预期的图表。当我的 Mac 尝试打开文件时,我收到的警告是文件可能已损坏,或者它是 Preview(或 Acrobat)无法识别的表单。以下是我的代码的高度编辑形式,其中包含有问题的部分。关于如何在 flexdashboard 中下载图表作为在 Shiny 中下载图表的任何指导?

---
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)
library(RColorBrewer)
source("MLHS_Distributions.R")
source("interp.R")
source("tooltips.R")
```

```{r Inputs}
downloadButton("downlaodReport","Price Comparision Report")

downloadHandler(filename = function() {
     filename = paste0("ModelReport-", 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--

plot(gg.prob.win.price)
})
```

标签: shinyflexdashboard

解决方案


推荐阅读