Is it possible to download a ggplotly()
object as .png like a ggplot()
object in a shiny application which you open in a browser. I have found some ways to download a ggplot but none for ggplotly. If there is no way is there some hacky alternative?
library(shiny)
library(plotly)
ui <- fluidPage(
plotlyOutput("plot"),
verbatimTextOutput("event"),
downloadButton("download","Download Plot")
)
server <- function(input, output) {
# renderPlotly() also understands ggplot2 objects!
save<-reactive({
plot_ly(mtcars, x = ~mpg, y = ~wt)
})
output$plot <- renderPlotly({
ggplotly(save())
})
output$download <- downloadHandler(
filename = function() {
paste("down", ".png", sep="")
},
content = function(file) {
ggsave(file, plot = save())
}
)
}
shinyApp(ui, server)