diff --git a/main/coverage-report/index.html b/main/coverage-report/index.html index fe680d33..7669978e 100644 --- a/main/coverage-report/index.html +++ b/main/coverage-report/index.html @@ -106,8 +106,8 @@

teal.reporter coverage - 82.57%

-
- +
+
@@ -118,2636 +118,2748 @@

teal.reporter coverage - 82.57%

1 -
#' Reporter Previewer User Interface
+
#' Report previewer module
2 -
#' @description `r lifecycle::badge("experimental")`
+
#'
3 -
#' reporter previewer user interface to visualize and manipulate the already added report Cards
+
#' @description `r lifecycle::badge("experimental")`
4 -
#' @param id `character(1)` this `shiny` module's id.
+
#'
5 -
#' @export
+
#' Module offers functionalities to visualize, manipulate,
6 -
reporter_previewer_ui <- function(id) {
+
#' and interact with report cards that have been added to a report.
- + 7 - 1x + -
  ns <- shiny::NS(id)
+
#' It includes a previewer interface to see the cards and options to modify the report before downloading.
8 -

+                      
#'
- + 9 - 1x + -
  shiny::fluidRow(
+
#' For more details see the vignette: `vignette("previewerReporter", "teal.reporter")`.
- + 10 - 1x + -
    add_previewer_js(ns),
+
#'
- + 11 - 1x + -
    add_previewer_css(),
+
#' @details `r global_knitr_details()`
- + 12 - 1x + -
    shiny::tagList(
+
#'
- + 13 - 1x + -
      shiny::tags$div(
+
#' @name reporter_previewer
- + 14 - 1x + -
        class = "col-md-3",
+
#'
- + 15 - 1x + -
        shiny::tags$div(class = "well", shiny::uiOutput(ns("encoding")))
+
#' @param id (`character(1)`) `shiny` module instance id.
16 -
      ),
+
#' @param reporter (`Reporter`) instance.
- + 17 - 1x + -
      shiny::tags$div(
+
#' @param global_knitr (`list`) of `knitr` parameters (passed to `knitr::opts_chunk$set`)
- + 18 - 1x + -
        class = "col-md-9",
+
#'  for customizing the rendering process.
- + 19 - 1x + -
        shiny::tags$div(
+
#' @inheritParams reporter_download_inputs
- + 20 - 1x + -
          id = "reporter_previewer",
+
#'
- + 21 - 1x + -
          shiny::uiOutput(ns("pcards"))
+
#' @return `NULL`.
22 -
        )
+
NULL
23 -
      )
+

                     
                   
                   
                     24
                     
                     
-                      
    )
+
#' @rdname reporter_previewer
25 -
  )
+
#' @export
26 -
}
+
reporter_previewer_ui <- function(id) {
- + 27 - + 1x -

+                      
  ns <- shiny::NS(id)
28 -
#' Reporter Previewer Server
+

                     
                   
-                  
+                  
                     29
-                    
+                    1x
                     
-                      
#' @description `r lifecycle::badge("experimental")`
+
  shiny::fluidRow(
- + 30 - + 1x -
#' server supporting the functionalities of the reporter previewer
+
    add_previewer_js(ns),
- + 31 + 1x + +
    add_previewer_css(),
+ + + + 32 + 1x + +
    shiny::tagList(
+ + + + 33 + 1x + +
      shiny::tags$div(
+ + + + 34 + 1x + +
        class = "col-md-3",
+ + + + 35 + 1x + +
        shiny::tags$div(class = "well", shiny::uiOutput(ns("encoding")))
+ + + + 36 -
#' For more details see the vignette: `vignette("previewerReporter", "teal.reporter")`.
+
      ),
+ + + + 37 + 1x + +
      shiny::tags$div(
+ + + + 38 + 1x + +
        class = "col-md-9",
+ + + + 39 + 1x + +
        shiny::tags$div(
+ + + + 40 + 1x + +
          id = "reporter_previewer",
+ + + + 41 + 1x + +
          shiny::uiOutput(ns("pcards"))
- 32 + 42 -
#' @param id `character(1)` this `shiny` module's id.
+
        )
- 33 + 43 -
#' @param reporter `Reporter` instance
+
      )
- 34 + 44 -
#' @param global_knitr `list` a of `knitr` parameters (passed to `knitr::opts_chunk$set`)
+
    )
- 35 + 45 -
#'  for customizing the rendering process.
+
  )
- 36 + 46 -
#' @inheritParams reporter_download_inputs
+
}
- 37 + 47 -
#' @details `r global_knitr_details()`
+

                     
                   
                   
-                    38
+                    48
                     
                     
-                      
#'
+
#' @rdname reporter_previewer
- 39 + 49
#' @export
- 40 + 50
reporter_previewer_srv <- function(id,
- 41 + 51
                                   reporter,
- 42 + 52
                                   global_knitr = getOption("teal.reporter.global_knitr"),
- 43 + 53
                                   rmd_output = c(
- 44 + 54
                                     "html" = "html_document", "pdf" = "pdf_document",
- 45 + 55
                                     "powerpoint" = "powerpoint_presentation",
- 46 + 56
                                     "word" = "word_document"
- 47 + 57
                                   ), rmd_yaml_args = list(
- 48 + 58
                                     author = "NEST", title = "Report",
- 49 + 59
                                     date = as.character(Sys.Date()), output = "html_document",
- 50 + 60
                                     toc = FALSE
- 51 + 61
                                   )) {
- 52 + 62 12x
  checkmate::assert_class(reporter, "Reporter")
- 53 + 63 12x
  checkmate::assert_subset(names(global_knitr), names(knitr::opts_chunk$get()))
- 54 + 64 12x
  checkmate::assert_subset(
- 55 + 65 12x
    rmd_output,
- 56 + 66 12x
    c(
- 57 + 67 12x
      "html_document", "pdf_document",
- 58 + 68 12x
      "powerpoint_presentation", "word_document"
- 59 + 69
    ),
- 60 + 70 12x
    empty.ok = FALSE
- 61 + 71
  )
- 62 + 72 12x
  checkmate::assert_list(rmd_yaml_args, names = "named")
- 63 + 73 12x
  checkmate::assert_names(
- 64 + 74 12x
    names(rmd_yaml_args),
- 65 + 75 12x
    subset.of = c("author", "title", "date", "output", "toc"),
- 66 + 76 12x
    must.include = "output"
- 67 + 77
  )
- 68 + 78 10x
  checkmate::assert_true(rmd_yaml_args[["output"]] %in% rmd_output)
- 69 + 79

                     
                   
                   
-                    70
+                    80
                     9x
                     
                       
  shiny::moduleServer(
- 71 + 81 9x
    id,
- 72 + 82 9x
    function(input, output, session) {
- 73 + 83 9x
      ns <- session$ns
- 74 + 84

                     
                   
                   
-                    75
+                    85
                     9x
                     
                       
      teal.reporter::reset_report_button_srv("resetButtonPreviewer", reporter)
- 76 + 86

                     
                   
                   
-                    77
+                    87
                     9x
                     
                       
      output$encoding <- shiny::renderUI({
- 78 + 88 7x
        reporter$get_reactive_add_card()
- 79 + 89 7x
        shiny::tagList(
- 80 + 90 7x
          shiny::tags$h3("Download the Report"),
- 81 + 91 7x
          shiny::tags$hr(),
- 82 + 92 7x
          reporter_download_inputs(
- 83 + 93 7x
            rmd_yaml_args = rmd_yaml_args,
- 84 + 94 7x
            rmd_output = rmd_output,
- 85 + 95 7x
            showrcode = any_rcode_block(reporter),
- 86 + 96 7x
            session = session
- 87 + 97
          ),
- 88 + 98 7x
          htmltools::tagAppendAttributes(
- 89 + 99 7x
            shiny::tags$a(
- 90 + 100 7x
              id = ns("download_data_prev"),
- 91 + 101 7x
              class = "btn btn-primary shiny-download-link",
- 92 + 102 7x
              href = "",
- 93 + 103 7x
              target = "_blank",
- 94 + 104 7x
              download = NA,
- 95 + 105 7x
              shiny::tags$span("Download Report", shiny::icon("download"))
- 96 + 106
            ),
- 97 + 107 7x
            class = if (length(reporter$get_cards())) "" else "disabled"
- 98 + 108
          ),
- 99 + 109 7x
          teal.reporter::reset_report_button_ui(ns("resetButtonPreviewer"), label = "Reset Report")
- 100 + 110
        )
- 101 + 111
      })
- 102 + 112

                     
                   
                   
-                    103
+                    113
                     9x
                     
                       
      output$pcards <- shiny::renderUI({
- 104 + 114 9x
        reporter$get_reactive_add_card()
- 105 + 115 9x
        input$card_remove_id
- 106 + 116 9x
        input$card_down_id
- 107 + 117 9x
        input$card_up_id
- 108 + 118

                     
                   
                   
-                    109
+                    119
                     9x
                     
                       
        cards <- reporter$get_cards()
- 110 + 120

                     
                   
                   
-                    111
+                    121
                     9x
                     
                       
        if (length(cards)) {
- 112 + 122 8x
          shiny::tags$div(
- 113 + 123 8x
            class = "panel-group accordion",
- 114 + 124 8x
            id = "reporter_previewer_panel",
- 115 + 125 8x
            lapply(seq_along(cards), function(ic) {
- 116 + 126 14x
              previewer_collapse_item(ic, cards[[ic]]$get_name(), cards[[ic]]$get_content())
- 117 + 127
            })
- 118 + 128
          )
- 119 + 129
        } else {
- 120 + 130 1x
          shiny::tags$div(
- 121 + 131 1x
            id = "reporter_previewer_panel_no_cards",
- 122 + 132 1x
            shiny::tags$p(
- 123 + 133 1x
              class = "text-danger mt-4",
- 124 + 134 1x
              shiny::tags$strong("No Cards added")
- 125 + 135
            )
- 126 + 136
          )
- 127 + 137
        }
- 128 + 138
      })
- 129 + 139

                     
                   
                   
-                    130
+                    140
                     9x
                     
                       
      shiny::observeEvent(input$card_remove_id, {
- 131 + 141 1x
        shiny::showModal(
- 132 + 142 1x
          shiny::modalDialog(
- 133 + 143 1x
            title = "Remove the Report Card",
- 134 + 144 1x
            shiny::tags$p(
- 135 + 145 1x
              shiny::HTML(
- 136 + 146 1x
                sprintf(
- 137 + 147 1x
                  "Do you really want to remove <strong>the card %s</strong> from the Report?",
- 138 + 148 1x
                  input$card_remove_id
- 139 + 149
                )
- 140 + 150
              )
- 141 + 151
            ),
- 142 + 152 1x
            footer = shiny::tagList(
- 143 + 153 1x
              shiny::tags$button(
- 144 + 154 1x
                type = "button",
- 145 + 155 1x
                class = "btn btn-secondary",
- 146 + 156 1x
                `data-dismiss` = "modal",
- 147 + 157 1x
                `data-bs-dismiss` = "modal",
- 148 + 158 1x
                NULL,
- 149 + 159 1x
                "Cancel"
- 150 + 160
              ),
- 151 + 161 1x
              shiny::actionButton(ns("remove_card_ok"), "OK", class = "btn-danger")
- 152 + 162
            )
- 153 + 163
          )
- 154 + 164
        )
- 155 + 165
      })
- 156 + 166

                     
                   
                   
-                    157
+                    167
                     9x
                     
                       
      shiny::observeEvent(input$remove_card_ok, {
- 158 + 168 1x
        reporter$remove_cards(input$card_remove_id)
- 159 + 169 1x
        shiny::removeModal()
- 160 + 170
      })
- 161 + 171

                     
                   
                   
-                    162
+                    172
                     9x
                     
                       
      shiny::observeEvent(input$card_up_id, {
- 163 + 173 3x
        if (input$card_up_id > 1) {
- 164 + 174 2x
          reporter$swap_cards(
- 165 + 175 2x
            as.integer(input$card_up_id),
- 166 + 176 2x
            as.integer(input$card_up_id - 1)
- 167 + 177
          )
- 168 + 178
        }
- 169 + 179
      })
- 170 + 180

                     
                   
                   
-                    171
+                    181
                     9x
                     
                       
      shiny::observeEvent(input$card_down_id, {
- 172 + 182 3x
        if (input$card_down_id < length(reporter$get_cards())) {
- 173 + 183 2x
          reporter$swap_cards(
- 174 + 184 2x
            as.integer(input$card_down_id),
- 175 + 185 2x
            as.integer(input$card_down_id + 1)
- 176 + 186
          )
- 177 + 187
        }
- 178 + 188
      })
- 179 + 189

                     
                   
                   
-                    180
+                    190
                     9x
                     
                       
      output$download_data_prev <- shiny::downloadHandler(
- 181 + 191 9x
        filename = function() {
- 182 + 192 1x
          paste("report_", format(Sys.time(), "%y%m%d%H%M%S"), ".zip", sep = "")
- 183 + 193
        },
- 184 + 194 9x
        content = function(file) {
- 185 + 195 1x
          shiny::showNotification("Rendering and Downloading the document.")
- 186 + 196 1x
          input_list <- lapply(names(rmd_yaml_args), function(x) input[[x]])
- 187 + 197 1x
          names(input_list) <- names(rmd_yaml_args)
- 188 + 198 !
          if (is.logical(input$showrcode)) global_knitr[["echo"]] <- input$showrcode
- 189 + 199 1x
          report_render_and_compress(reporter, input_list, global_knitr, file)
- 190 + 200
        },
- 191 + 201 9x
        contentType = "application/zip"
- 192 + 202
      )
- 193 + 203
    }
- 194 + 204
  )
- 195 + 205
}
- 196 + 206

                     
                   
                   
-                    197
+                    207
+                    
+                    
+                      
#' @noRd
+ + + + 208
#' @keywords internal
- 198 + 209
block_to_html <- function(b) {
- 199 + 210 42x
  b_content <- b$get_content()
- 200 + 211 42x
  if (inherits(b, "TextBlock")) {
- 201 + 212 28x
    switch(b$get_style(),
- 202 + 213 !
      header1 = shiny::tags$h1(b_content),
- 203 + 214 28x
      header2 = shiny::tags$h2(b_content),
- 204 + 215 !
      header3 = shiny::tags$h3(b_content),
- 205 + 216 !
      header4 = shiny::tags$h4(b_content),
- 206 + 217 !
      verbatim = shiny::tags$pre(b_content),
- 207 + 218 !
      shiny::tags$pre(b_content)
- 208 + 219
    )
- 209 + 220 14x
  } else if (inherits(b, "RcodeBlock")) {
- 210 + 221 !
    panel_item("R Code", shiny::tags$pre(b_content))
- 211 + 222 14x
  } else if (inherits(b, "PictureBlock")) {
- 212 + 223 14x
    shiny::tags$img(src = knitr::image_uri(b_content))
- 213 + 224 !
  } else if (inherits(b, "TableBlock")) {
- 214 + 225 !
    b_table <- readRDS(b_content)
- 215 + 226 !
    shiny::tags$pre(
- 216 + 227 !
      flextable::htmltools_value(b_table)
- 217 + 228
    )
- 218 + 229 !
  } else if (inherits(b, "NewpageBlock")) {
- 219 + 230 !
    shiny::tags$br()
- 220 + 231
  } else {
- 221 + 232 !
    stop("Unknown block class")
- 222 + 233
  }
- 223 + 234
}
- 224 + 235

                     
                   
                   
-                    225
+                    236
+                    
+                    
+                      
#' @noRd
+ + + + 237
#' @keywords internal
- 226 + 238
add_previewer_css <- function() {
- 227 + 239 1x
  shiny::tagList(
- 228 + 240 1x
    shiny::singleton(
- 229 + 241 1x
      shiny::tags$head(shiny::includeCSS(system.file("css/Previewer.css", package = "teal.reporter")))
- 230 + 242
    ),
- 231 + 243 1x
    shiny::singleton(
- 232 + 244 1x
      shiny::tags$head(shiny::includeCSS(system.file("css/custom.css", package = "teal.reporter")))
- 233 + 245
    )
- 234 + 246
  )
- 235 + 247
}
- 236 + 248

                     
                   
                   
-                    237
+                    249
+                    
+                    
+                      
#' @noRd
+ + + + 250
#' @keywords internal
- 238 + 251
add_previewer_js <- function(ns) {
- 239 + 252 1x
  shiny::singleton(
- 240 + 253 1x
    shiny::tags$head(shiny::tags$script(
- 241 + 254 1x
      shiny::HTML(sprintf('
- 242 + 255 1x
          $(document).ready(function(event) {
- 243 + 256 1x
            $("body").on("click", "span.card_remove_id", function() {
- 244 + 257 1x
              let val = $(this).data("cardid");
- 245 + 258 1x
              Shiny.setInputValue("%s", val, {priority: "event"});
- 246 + 259
            });
- 247 + 260

                     
                   
                   
-                    248
+                    261
                     1x
                     
                       
            $("body").on("click", "span.card_up_id", function() {
- 249 + 262 1x
              let val = $(this).data("cardid");
- 250 + 263 1x
              Shiny.setInputValue("%s", val, {priority: "event"});
- 251 + 264
            });
- 252 + 265

                     
                   
                   
-                    253
+                    266
                     1x
                     
                       
             $("body").on("click", "span.card_down_id", function() {
- 254 + 267 1x
              let val = $(this).data("cardid");
- 255 + 268 1x
              Shiny.setInputValue("%s", val, {priority: "event"});
- 256 + 269
             });
- 257 + 270
          });
- 258 + 271 1x
         ', ns("card_remove_id"), ns("card_up_id"), ns("card_down_id")))
- 259 + 272
    ))
- 260 + 273
  )
- 261 + 274
}
- 262 + 275

                     
                   
                   
-                    263
+                    276
+                    
+                    
+                      
#' @noRd
+ + + + 277
#' @keywords internal
- 264 + 278
nav_previewer_icon <- function(name, icon_name, idx, size = 1L) {
- 265 + 279 42x
  checkmate::assert_string(name)
- 266 + 280 42x
  checkmate::assert_string(icon_name)
- 267 + 281 42x
  checkmate::assert_int(size)
- 268 + 282

                     
                   
                   
-                    269
+                    283
                     42x
                     
                       
  shiny::tags$span(
- 270 + 284 42x
    class = paste(name, "icon_previewer"),
- 271 + 285
    # data field needed to record clicked card on the js side
- 272 + 286 42x
    `data-cardid` = idx,
- 273 + 287 42x
    shiny::icon(icon_name, sprintf("fa-%sx", size))
- 274 + 288
  )
- 275 + 289
}
- 276 + 290

                     
                   
                   
-                    277
+                    291
+                    
+                    
+                      
#' @noRd
+ + + + 292
#' @keywords internal
- 278 + 293
nav_previewer_icons <- function(idx, size = 1L) {
- 279 + 294 14x
  shiny::tags$span(
- 280 + 295 14x
    class = "preview_card_control",
- 281 + 296 14x
    nav_previewer_icon(name = "card_remove_id", icon_name = "xmark", idx = idx, size = size),
- 282 + 297 14x
    nav_previewer_icon(name = "card_up_id", icon_name = "arrow-up", idx = idx, size = size),
- 283 + 298 14x
    nav_previewer_icon(name = "card_down_id", icon_name = "arrow-down", idx = idx, size = size)
- 284 + 299
  )
- 285 + 300
}
- 286 + 301

                     
                   
                   
-                    287
+                    302
+                    
+                    
+                      
#' @noRd
+ + + + 303
#' @keywords internal
- 288 + 304
previewer_collapse_item <- function(idx, card_name, card_blocks) {
- 289 + 305 14x
  shiny::tags$div(.renderHook = function(x) {
- 290 + 306
    # get bs version
- 291 + 307 14x
    version <- get_bs_version()
- 292 + 308

                     
                   
                   
-                    293
+                    309
                     14x
                     
                       
    if (version == "3") {
- 294 + 310 14x
      shiny::tags$div(
- 295 + 311 14x
        id = paste0("panel_card_", idx),
- 296 + 312 14x
        class = "panel panel-default",
- 297 + 313 14x
        shiny::tags$div(
- 298 + 314 14x
          class = "panel-heading overflow-auto",
- 299 + 315 14x
          shiny::tags$div(
- 300 + 316 14x
            class = "panel-title",
- 301 + 317 14x
            shiny::tags$span(
- 302 + 318 14x
              nav_previewer_icons(idx = idx),
- 303 + 319 14x
              shiny::tags$a(
- 304 + 320 14x
                class = "accordion-toggle block py-3 px-4 -my-3 -mx-4",
- 305 + 321 14x
                `data-toggle` = "collapse",
- 306 + 322 14x
                `data-parent` = "#reporter_previewer_panel",
- 307 + 323 14x
                href = paste0("#collapse", idx),
- 308 + 324 14x
                shiny::tags$h4(paste0("Card ", idx, ": ", card_name), shiny::icon("caret-down"))
- 309 + 325
              )
- 310 + 326
            )
- 311 + 327
          )
- 312 + 328
        ),
- 313 + 329 14x
        shiny::tags$div(
- 314 + 330 14x
          id = paste0("collapse", idx), class = "collapse out",
- 315 + 331 14x
          shiny::tags$div(
- 316 + 332 14x
            class = "panel-body",
- 317 + 333 14x
            shiny::tags$div(
- 318 + 334 14x
              id = paste0("card", idx),
- 319 + 335 14x
              lapply(
- 320 + 336 14x
                card_blocks,
- 321 + 337 14x
                function(b) {
- 322 + 338 42x
                  block_to_html(b)
- 323 + 339
                }
- 324 + 340
              )
- 325 + 341
            )
- 326 + 342
          )
- 327 + 343
        )
- 328 + 344
      )
- 329 + 345
    } else {
- 330 + 346 !
      shiny::tags$div(
- 331 + 347 !
        id = paste0("panel_card_", idx),
- 332 + 348 !
        class = "card",
- 333 + 349 !
        shiny::tags$div(
- 334 + 350 !
          class = "overflow-auto",
- 335 + 351 !
          shiny::tags$div(
- 336 + 352 !
            class = "card-header",
- 337 + 353 !
            shiny::tags$span(
- 338 + 354 !
              nav_previewer_icons(idx = idx),
- 339 + 355 !
              shiny::tags$a(
- 340 + 356 !
                class = "accordion-toggle block py-3 px-4 -my-3 -mx-4",
- 341 + 357
                # bs4
- 342 + 358 !
                `data-toggle` = "collapse",
- 343 + 359
                # bs5
- 344 + 360 !
                `data-bs-toggle` = "collapse",
- 345 + 361 !
                href = paste0("#collapse", idx),
- 346 + 362 !
                shiny::tags$h4(
- 347 + 363 !
                  paste0("Card ", idx, ": ", card_name),
- 348 + 364 !
                  shiny::icon("caret-down")
- 349 + 365
                )
- 350 + 366
              )
- 351 + 367
            )
- 352 + 368
          )
- 353 + 369
        ),
- 354 + 370 !
        shiny::tags$div(
- 355 + 371 !
          id = paste0("collapse", idx),
- 356 + 372 !
          class = "collapse out",
- 357 + 373
          # bs4
- 358 + 374 !
          `data-parent` = "#reporter_previewer_panel",
- 359 + 375
          # bs5
- 360 + 376 !
          `data-bs-parent` = "#reporter_previewer_panel",
- 361 + 377 !
          shiny::tags$div(
- 362 + 378 !
            class = "card-body",
- 363 + 379 !
            shiny::tags$div(
- 364 + 380 !
              id = paste0("card", idx),
- 365 + 381 !
              lapply(
- 366 + 382 !
                card_blocks,
- 367 + 383 !
                function(b) {
- 368 + 384 !
                  block_to_html(b)
- 369 + 385
                }
- 370 + 386
              )
- 371 + 387
            )
- 372 + 388
          )
- 373 + 389
        )
- 374 + 390
      )
- 375 + 391
    }
- 376 + 392
  })
- 377 + 393
}
@@ -2756,98 +2868,98 @@

teal.reporter coverage - 82.57%

-