From d884231b62a91a056b4a36c5c7d956bb8bdca407 Mon Sep 17 00:00:00 2001 From: Kannan Date: Wed, 18 Dec 2024 18:08:45 +0530 Subject: [PATCH] Advanced Report #322 --- app/server.R | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++-- app/ui.R | 36 ++++++++----------------- 2 files changed, 83 insertions(+), 27 deletions(-) diff --git a/app/server.R b/app/server.R index c1b1546..50a2c1b 100644 --- a/app/server.R +++ b/app/server.R @@ -280,6 +280,11 @@ server <- function(input, output, session) { condition = input$select, shinyjs::disable("report") ) + toggleState( + id = "advreport", + condition = input$select, + shinyjs::disable("advreport") + ) toggleState( id = "pptreport", condition = input$select, @@ -929,6 +934,7 @@ server <- function(input, output, session) { status = "warning", width = "100%", shinyjs::disable("report"), + shinyjs::disable("advreport"), shinyjs::disable("pptreport"), shinyjs::disable('download_missing'), shinyjs::disable("download_data_1"), @@ -957,6 +963,11 @@ server <- function(input, output, session) { condition = length(input$countries) >= 10, shinyjs::disable("report"), ) + toggleState( + id = "select", + condition = length(input$countries) >= 10, + shinyjs::disable("advreport"), + ) toggleState( id = "select", condition = length(input$countries) >= 10, @@ -2565,7 +2576,7 @@ server <- function(input, output, session) { family_order = family_order, global_data = global_data, family_order = family_order, - download_opt = input$download_Opt, + download_opt = FALSE, compiled_indicators = raw_data, db_variables = db_variables ) @@ -2580,7 +2591,66 @@ server <- function(input, output, session) { ) } ) - + + #Advanced Report + output$advreport <- downloadHandler( + filename = + reactive( + paste0( + "CLIAR-benchmarking-Advanced-Report-", + base_country(), + ".docx" + ) + ), + content = function(file) { + show_modal_spinner( + color = "#17a2b8", + text = "Compiling report", + ) + + on.exit(remove_modal_spinner()) + + tmp_dir <- tempdir() + + tempReport <- file.path(tmp_dir, "report.Rmd") + + file.copy("www/", tmp_dir, recursive = TRUE) + file.copy("report.Rmd", tempReport, overwrite = TRUE) + + params <- + list( + base_country = base_country(), + comparison_countries = input$countries, + data = data_avg(), + wb_country_list = country_list, + family_data = data_family(), + data_dyn = data_dyn(), + data_dyn_avg = data_dyn_avg(), + family_data_dyn = data_family_dyn(), + rank = input$rank, + definitions = definitions, + variable_names = variable_names, + dots = input$benchmark_dots, + group_median = input$benchmark_median, + threshold = input$threshold, + family_order = family_order, + global_data = global_data, + family_order = family_order, + download_opt = TRUE, + compiled_indicators = raw_data, + db_variables = db_variables + ) + + + rmarkdown::render( + tempReport, + output_file = file, + params = params, + envir = new.env(parent = globalenv()), + knit_root_dir = getwd() + ) + } + ) # Missingness Report ================================================================================ diff --git a/app/ui.R b/app/ui.R index a497b47..6b8097a 100644 --- a/app/ui.R +++ b/app/ui.R @@ -659,7 +659,7 @@ ui <- fluidRow( id = "download_reports", column( - width = 4, + width = 3, shinyjs::disabled( downloadButton( "report", @@ -667,34 +667,20 @@ ui <- style = "width:100%; background-color: #204d74; color: white" ) ), - shiny::fluidRow( - column( - width = 12, - helper( - shiny_tag = tags$b("Advanced Report Download"), - type = "inline", - icon = "circle-question", - title = "Pre-populated reports and data", - content = c( - "The Advanced Report includes all available dynamic graphs for the selected base country. - These plots take a lot of time to produce, so please wait about 10 minutes for the advanced report to download" - ), - buttonLabel = "Close", - fade = T, - size = "s" - ), - prettyCheckbox( - inputId = "download_Opt", - label = "Advanced Report (~10min)", - value = FALSE, - icon = icon("check"), - status = "success" - ) + + ), + column( + width = 3, + shinyjs::disabled( + downloadButton( + "advreport", + "Advanced Report", + style = "width:100%; background-color: #204d74; color: white" ) ) ), column( - width = 4, + width = 3, shinyjs::disabled( downloadButton( "pptreport",