如何在不重新定义的情况下调用使用反应式函数创建的图表,以供downloadHandler
使用?
以下是一个无法工作的示例:
# Part of server.R
output$tgPlot <- renderPlot({
plot1 <-ggplot(iris[iris$Species==input$species,])+geom_point(aes(Sepal.Length ,Sepal.Width))
print(plot1)
} )
output$plotsave <- downloadHandler(
filename = 'plot.pdf',
content = function(file){
pdf(file = file, width=12, height=4)
tgPlot()
dev.off()
}
)
为什么无法在
downloadHandler
中调用tgPlot()
?是否有其他方法?
output$tgPlot
,类似于此处用于数据集的方法。https://dev59.com/H2Yr5IYBdhLWcg3wi6zd。当您有许多不同的条件图作为`output$tgPlot`的可能输出时,这将非常方便。 - Jonas TundorenderPlot
),正在呈现的是PNG,在另一个情况下,它是PDF,这些是两个完全不同的操作,只是恰好共享一些公共逻辑(即tqPlot
)。 - Joe Cheng