Hi,
I'm trying to make an app where the user can download a heatmap as png.
I've been trying to achieve this with ggsave but it's not working.
An example:
library(shiny)
library(ggplot2)
library(gplots)
runApp(list(
ui = fluidPage(downloadButton('foo'),
plotOutput("my_plot")
),
server = function(input, output) {
my_plot <- reactive({
x <- as.matrix(mtcars)
heatmap.2(x)
})
output$my_plot <- renderPlot({
my_plot()
})
output$foo = downloadHandler(
filename = 'test.png',
content = function(file) {
device <- function(..., width, height) {
grDevices::png(..., width = width, height = height,
res = 300, units = "in")
}
ggsave(file, plot = eval(my_plot()$call), device = device)
})
}
))
Anybody have an idea?