R/summaryTable.R

summaryTableUI <- function(id){
  ns <- NS(id)
  tagList(
    DT::dataTableOutput(ns("table")),
    downloadButton(ns("download"))
  )
}

summaryTable <- function(input, output, session,
                         criteria, scenarios, scoring){



  technical <- reactiveValues()

  output$table <- DT::renderDataTable({
    technical$data
  },
  rownames = F,
  extensions = c('Responsive'),
  options = list(dom = "tip")
  )


  observe({
    req(scoring$data)
    req(scenarios$data)
    req(criteria$static)
    if("Threshold" %in% criteria$options){
      df <- criteria$static[,c("Description", "Threshold", "Weight")]
      df$Threshold <- as.numeric(as.character(df$Threshold))
    } else{
      df <- criteria$static[,c("Description", "Weight")]
    }
    df$ID <- as.integer(row.names(df))


    df <- scenarios$data %>%
      tidyr::gather("Scenario", "Confidence", -"ID", -"Description") %>%
      dplyr::select(-Description) %>%
      dplyr::left_join(df, "ID") %>%
      dplyr::left_join(scoring$data, by="Confidence") %>%
      dplyr::mutate("Weight" = round(Weight,2)) %>%
      dplyr::mutate("Weighted Score" = Weight * Score / 10)

    if("Threshold" %in% criteria$options){
      df <- df %>% dplyr::mutate(
        "Compliant" = Score >= Threshold
        )
    }
    technical$data <- df
  })


  output$download <-  downloadHandler(
    filename = paste0(Sys.Date(), "_Tender Evaluation Scenario Analysis_OSC.csv"),
    content = function(file){
      write.csv(technical$data, file, row.names=F)
    }
  )

  return(technical)

}
lajh87/tessa documentation built on July 6, 2019, 12:06 a.m.