Skip to content

Instantly share code, notes, and snippets.

@ColinFay
Last active March 30, 2021 11:32
Show Gist options
  • Save ColinFay/4ff2721901c169703da049bce49bd5e2 to your computer and use it in GitHub Desktop.
Save ColinFay/4ff2721901c169703da049bce49bd5e2 to your computer and use it in GitHub Desktop.
library(shiny)
library(ggplot2)
ui <- function(request){
tagList(
h2("Click on the plot to download it"),
tags$button(
"Click here to download the plot",
onclick = 'var a = document.createElement("a"); a.href = $("#plop").find("img").attr("src"); a.download = "Image.png"; a.click(); '
),
plotOutput("plop")
)
}
server <- function(
input,
output,
session
){
output$plop <- renderPlot({
ggplot(mtcars,aes(gear, carb)) +
geom_point()
})
}
shinyApp(ui, server)
library(shiny)
library(ggplot2)
ui <- function(request){
tagList(
h2("Click on the plot to download it"),
plotOutput("plop") %>%
tagAppendAttributes(
onclick = 'var a = document.createElement("a"); a.href = $(this).find("img").attr("src"); a.download = "Image.png"; a.click(); '
)
)
}
server <- function(
input,
output,
session
){
output$plop <- renderPlot({
ggplot(mtcars,aes(gear, carb)) +
geom_point()
})
}
shinyApp(ui, server)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment