Skip to content

Commit

Permalink
Merge pull request #122 from openpharma/ac-96
Browse files Browse the repository at this point in the history
Improved Excel button
  • Loading branch information
aclark02-arcus authored Nov 11, 2024
2 parents 37d556e + 130b274 commit bd9d8e0
Show file tree
Hide file tree
Showing 19 changed files with 610 additions and 18 deletions.
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
Package: clinsight
Title: ClinSight
Version: 0.1.0.9008
DevexVersion: 9000
Authors@R: c(
person("Leonard Daniël", "Samson", , "[email protected]", role = c("cre", "aut"),
comment = c(ORCID = "0000-0002-6252-7639")),
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@

- When using the `shinyproxy` deployment configuration, the user name is now expected to be base64 encoded, and will now be base64 encoded by `clinsight` by default, so that the app can also handle non-ASCII signs in user names that are stored in HTTP headers. To display the user name correctly, use base64 encoding in the `application.yml` in ShinyProxy settings (for example: `http-headers.X_SP_USERNAME: "#{T(java.util.Base64).getEncoder().encodeToString(oidcUser.getFullName().getBytes())}"`).

## `devex` changes
- Added `Excel` download button to Queries table & patient listings that need review.
- Added helper function to automatically determine when adding said excel button is appropriate.

# clinsight 0.1.0

## Changed
Expand Down
29 changes: 29 additions & 0 deletions R/fct_data_helpers.R
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,35 @@ add_missing_columns <- function(
data
}

#' Configure DT helper
#'
#' Small wrapper that helps handle some messiness preparing the correct `DT`
#' dom, extensions, & options when needed. Specifically, when & how to add an
#' Excel download button.
#'
#' @param data A data frame used for display in a DT table. Number of rows will
#' be assessed
#' @param table_name character string, usually the form name
#'
#' @keywords internal
#' @return list with three named objects: `dom`, `exts`, and `opts`
dt_config <- function(data, table_name = "form") {
default_args<- formals(datatable_custom)
if(nrow(data) > 0 & isTRUE(get_golem_config("allow_listing_download"))) {
dt_dom <- 'Bfti'
dt_exts <- c("Buttons", eval(default_args$extensions))
dt_opts <- list(buttons=list(list(extend = 'excel',
text = '<i class="fa-solid fa-download"></i>',
filename = paste("clinsight", gsub(" ", "-", table_name), sep = ".")
)))
} else {
dt_dom <- default_args$dom |> eval()
dt_exts <- default_args$extensions |> eval()
dt_opts <- default_args$options |> eval()
}
return(list(dom = dt_dom, exts = dt_exts, opts = dt_opts))
}

#' Custom interactive datatable
#'
#' Small wrapper around [DT::datatable()]. Will be used to create tables in a
Expand Down
22 changes: 18 additions & 4 deletions R/mod_common_forms.R
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,16 @@ mod_common_forms_server <- function(
)) |>
adjust_colnames("^SAE ")
if(!input$show_all_data) SAE_data$subject_id <- NULL
datatable_custom(SAE_data, rename_vars = table_names, rownames= FALSE,
title = "Serious Adverse Events", escape = FALSE)

# determine DT dom / exts / opts
DT <- dt_config(SAE_data,
table_name = paste("SAE", ifelse(input$show_all_data,
"all_patients", r$subject_id), sep = "."))
datatable_custom(
SAE_data, rename_vars = table_names, rownames= FALSE,
title = "Serious Adverse Events", escape = FALSE,
dom = DT$dom, extensions = DT$exts, options = DT$opts
)
})

output[["common_form_table"]] <- DT::renderDT({
Expand All @@ -145,8 +153,14 @@ mod_common_forms_server <- function(
dplyr::select(-dplyr::starts_with("SAE"))
}
if(!input$show_all_data) df$subject_id <- NULL
datatable_custom(df, rename_vars = table_names, rownames= FALSE,
title = form, escape = FALSE)

# determine DT dom / exts / opts
DT <- dt_config(df,
table_name = paste(form, ifelse(input$show_all_data,
"all_patients", r$subject_id), sep = "."))
datatable_custom(
df, rename_vars = table_names, rownames= FALSE,title = form,
escape = FALSE, dom = DT$dom, extensions = DT$exts, options = DT$opts)
})

})
Expand Down
8 changes: 7 additions & 1 deletion R/mod_queries.R
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,17 @@ mod_queries_server <- function(id, r, navinfo, all_forms, db_path, table_names){
query_cols <- c("resolved", query_cols)
table_title <- "All queries"
}

# determine DT dom / exts / opts
DT <- dt_config(initial_queries()[query_cols],
table_name = paste(ifelse(input$show_resolved, "all", "open"),
"queries", sep = "."))
datatable_custom(
initial_queries()[query_cols],
table_names,
title = table_title,
callback = dblclick_to_form(ns("go_to_form"))
callback = dblclick_to_form(ns("go_to_form")),
dom = DT$dom, extensions = DT$exts, options = DT$opts
)
})

Expand Down
7 changes: 6 additions & 1 deletion R/mod_study_forms.R
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,12 @@ mod_study_forms_server <- function(

output[["table"]] <- DT::renderDT({
req(table_data_active())
datatable_custom(table_data_active(), table_names, escape = FALSE)
# determine DT dom / exts / opts
DT <- dt_config(table_data_active(),
table_name = paste(form, ifelse(input$show_all,
"all_patients", r$subject_id), sep = "."))
datatable_custom(table_data_active(), table_names, escape = FALSE,
dom = DT$dom, extensions = DT$exts, options = DT$opts)
})

if(form %in% c("Vital signs", "Vitals adjusted")){
Expand Down
5 changes: 5 additions & 0 deletions inst/app/www/custom.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@

.dataTables_wrapper .dt-buttons {
padding-left: 0.75em;
float: right;
}

.bslib-value-box .value-box-area {
padding: 0.1rem 0rem 0.1rem 1rem;
}
Expand Down
1 change: 1 addition & 0 deletions inst/golem-config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ default:
Medical Monitor: medical_monitor
Data Manager: data_manager
allow_to_review: [admin, medical_monitor]
allow_listing_download: TRUE
dev:
golem_wd: !expr golem::pkg_path()
test:
Expand Down
23 changes: 23 additions & 0 deletions man/dt_config.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 43 additions & 1 deletion tests/testthat/_snaps/app_feature_01/app-feature-1-002.json
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@
"filter": "none",
"vertical": false,
"extensions": [
"Buttons",
"Scroller",
"ColReorder"
],
Expand All @@ -251,8 +252,15 @@
"scrollResize": true,
"scrollCollapse": true,
"colReorder": true,
"buttons": [
{
"extend": "excel",
"text": "<i class=\"fa-solid fa-download\"><\/i>",
"filename": "clinsight.Adverse-events.BEL_04_772"
}
],
"initComplete": "function() {\n$(this.api().table().container()).find('.header').html(\"Adverse events\")\n}",
"dom": "f<\"header h5\">ti",
"dom": "Bf<\"header h5\">ti",
"columnDefs": [
{
"className": "dt-right",
Expand Down Expand Up @@ -389,6 +397,40 @@
"attachment": null,
"all_files": true
},
{
"name": "jszip",
"version": "1.13.6",
"src": {
"href": "jszip-1.13.6"
},
"meta": null,
"script": "jszip.min.js",
"stylesheet": null,
"head": null,
"attachment": null,
"package": null,
"all_files": false
},
{
"name": "dt-ext-buttons-bootstrap5",
"version": "1.13.6",
"src": {
"href": "dt-ext-buttons-bootstrap5-1.13.6"
},
"meta": null,
"script": [
"js/dataTables.buttons.min.js",
"js/buttons.html5.min.js",
"js/buttons.colVis.min.js",
"js/buttons.print.min.js",
"js/buttons.bootstrap5.min.js"
],
"stylesheet": "css/buttons.bootstrap5.min.css",
"head": null,
"attachment": null,
"package": null,
"all_files": false
},
{
"name": "dt-ext-scroller-bootstrap5",
"version": "1.13.6",
Expand Down
44 changes: 43 additions & 1 deletion tests/testthat/_snaps/app_feature_01/app-feature-1-003.json
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@
"filter": "none",
"vertical": false,
"extensions": [
"Buttons",
"Scroller",
"ColReorder"
],
Expand All @@ -251,8 +252,15 @@
"scrollResize": true,
"scrollCollapse": true,
"colReorder": true,
"buttons": [
{
"extend": "excel",
"text": "<i class=\"fa-solid fa-download\"><\/i>",
"filename": "clinsight.Adverse-events.BEL_04_772"
}
],
"initComplete": "function() {\n$(this.api().table().container()).find('.header').html(\"Adverse events\")\n}",
"dom": "f<\"header h5\">ti",
"dom": "Bf<\"header h5\">ti",
"columnDefs": [
{
"className": "dt-right",
Expand Down Expand Up @@ -389,6 +397,40 @@
"attachment": null,
"all_files": true
},
{
"name": "jszip",
"version": "1.13.6",
"src": {
"href": "jszip-1.13.6"
},
"meta": null,
"script": "jszip.min.js",
"stylesheet": null,
"head": null,
"attachment": null,
"package": null,
"all_files": false
},
{
"name": "dt-ext-buttons-bootstrap5",
"version": "1.13.6",
"src": {
"href": "dt-ext-buttons-bootstrap5-1.13.6"
},
"meta": null,
"script": [
"js/dataTables.buttons.min.js",
"js/buttons.html5.min.js",
"js/buttons.colVis.min.js",
"js/buttons.print.min.js",
"js/buttons.bootstrap5.min.js"
],
"stylesheet": "css/buttons.bootstrap5.min.css",
"head": null,
"attachment": null,
"package": null,
"all_files": false
},
{
"name": "dt-ext-scroller-bootstrap5",
"version": "1.13.6",
Expand Down
Loading

0 comments on commit bd9d8e0

Please sign in to comment.