我对使用拼凑包来安排一组图感兴趣,最终用户可以使用下载按钮下载这些图。为简单起见,在此示例中,我仅显示了一个图。
示例脚本:
library(shiny)
library(tidyverse)
library(Cairo)
library(grDevices)
ui <- fluidPage(
mainPanel(
tabsetPanel(
tabPanel(
"PDF this plot with patchwork",plotOutput("diamonds"),downloadButton("downloadPlot","Download Plot")
)
)
)
)
server <- function(input,output,session){
output$diamonds <- renderPlot({
ggplot(diamonds,aes(x=carat,y=price,color=cut)) + geom_point() + geom_smooth()
})
output$downloadPlot <- downloadHandler(
filename = "my_plot.pdf",content = function(file){
cairo_pdf(filename = file,width = 18,height = 10,pointsize = 12,family = "sans",bg = "transparent",antialias = "subpixel",fallback_resolution = 300)
patchwork::wrap_plots(ggplot(diamonds,color=cut)) + geom_point() + geom_smooth())
dev.off()
},contentType = "application/pdf"
)
}
shinyApp(ui=ui,server=server)
在这种情况下,生成的pdf为空白。我查看了this的相关问题,如果我将patchwork::wrap_plots
替换为gridExtra::grid.arrange
,则该应用程序现在可以运行了,但是出于很多原因,我宁愿使用patchwork
我没有精选(剧情命名,字幕等)。对于我的真实脚本,我对使用Markdown也不感兴趣。