R/mod_dl.R

Defines functions mod_dl_server mod_dl_ui

Documented in mod_dl_server mod_dl_ui

# Module UI

#' @title   mod_dl_ui and mod_dl_server
#' @description  A shiny Module.
#'
#' @param id shiny id
#' @param input internal
#' @param output internal
#' @param session internal
#'
#' @rdname mod_dl
#'
#' @keywords internal
#' @export 
#' @importFrom shiny NS tagList tags fluidRow downloadButton 
mod_dl_ui <- function(id){
  ns <- NS(id)
  tagList(
    tags$details(
      summary("Download the hex"),
      tags$div(
        class = "innerrounded rounded",
        align = "center",
        fluidRow(
          col_12(
            downloadButton(
              ns("dl"), 
              "Download the Hex"
            )
          ) 
        )
      )
    )
  )
}

# Module Server

#' @rdname mod_dl
#' @export
#' @keywords internal
#' @importFrom whereami cat_where whereami
#' @importFrom shiny downloadHandler
mod_dl_server <- function(
  input, 
  output, 
  session, 
  img
){
  ns <- session$ns
  
  output$dl <- downloadHandler(
    filename = function() {
      paste('hex-', img$package, '.png', sep='')
    },
    content = function(con) {
      whereami::cat_where(whereami::whereami())
      img$render(con)
    }
  )
  
}
ColinFay/hexmake documentation built on Feb. 2, 2023, 7:55 a.m.