R/reportModule.R

reportMenuUI <- function(id){
  ns <- NS(id)
    tags$li(
      class = "dropdown",
      actionLink(
        inputId = ns("report_menu"),
        label = NULL,
        icon = icon("download")
      )
    )
}

reportModule <- function(input, output, session, strategy, results, criteria){

  ns <- session$ns

  observeEvent(input$report_menu,{
    showModal(
      modalDialog(
        title = list(icon("download"), "Download Report (Work in Progress)"),
        size = "m",
        radioButtons(ns("report_type"), "Report Type",c("Single")),
        radioButtons(ns("report_format"), "Report Type",c("HTML Document")),
        helpText(paste0("When complete this module will contain HTML and .docx reports",
                        " and comparative analysis")),
        footer = tagList(
          downloadButton(ns("download")),
          modalButton("Close", icon("close"))
        )
      )
    )
  })


  # This needs to be converted to a module.. see online.
  output$download <-  downloadHandler(
    # For PDF output, change this to "report.pdf"
    filename = paste0(Sys.Date(),"_tender_evaluation_report", ".html"),
    content = function(file) {
      # Copy the report file to a temporary directory before processing it, in
      # case we don't have write permissions to the current working dir (which
      # can happen when deployed).
      tempReport <- file.path(tempdir(), "report.Rmd")
      file.copy(system.file("report_templates/report.Rmd", package="tessa"), tempReport, overwrite = TRUE)
      # Set up parameters to pass to Rmd document
      params <- list(strategy = strategy,
                     results = results,
                     criteria = criteria)

      # Knit the document, passing in the `params` list, and eval it in a
      # child of the global environment (this isolates the code in the document
      # from the code in this app).
      rmarkdown::render(tempReport, output_file = file,
                        params = params,
                        envir = new.env(parent = globalenv())
      )
    }
  )
}
lajh87/tessa documentation built on July 6, 2019, 12:06 a.m.