R/mod_downloadImage.R

Defines functions mod_downloadImage_server mod_downloadImage_ui

#' downloadImage UI Function
#'
#' @description A shiny Module.
#'
#' @param id,input,output,session Internal parameters for {shiny}.
#'
#' @noRd 
#'
#' @importFrom shiny NS tagList 
mod_downloadImage_ui <- function(id){
  ns <- NS(id)
  tagList(
    downloadButton(ns("downloadPlot"), "Download the plot"))
}
    
#' downloadImage Server Function
#'
#' @noRd 
mod_downloadImage_server <- function(input, output, session, treePlotOut){
  ns <- session$ns
  # 
  output$downloadPlot <- downloadHandler(
    filename = function() {
      paste("data-", Sys.Date(), ".png", sep="")
    },
    content = function(file) {
      ggplot2::ggsave(file, plot = treePlotOut(), device = "png")
    }
  )
}
    
## To be copied in the UI
# mod_downloadImage_ui("downloadImage_ui_1")
    
## To be copied in the server
# callModule(mod_downloadImage_server, "downloadImage_ui_1")
 
jennahamlin/annoatater documentation built on Aug. 30, 2020, 10:51 p.m.