Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Table download button - suggestion for change #157

Merged
merged 6 commits into from
Jan 14, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Renaming table_name argument of datatable_custom to export label to a…
…void confusion
LDSamson committed Jan 14, 2025

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit 90e8b81bd1a607468263b6769ccbf1d9d45aa199
15 changes: 7 additions & 8 deletions R/fct_data_helpers.R
Original file line number Diff line number Diff line change
@@ -536,9 +536,8 @@ add_missing_columns <- function(
#' the table as an Excel file. Defaults to the `allow_listing_download`
#' configuration option in `golem-config.yml`, but can be overwritten here if
#' needed.
#' @param table_name Character string with the table name. Only used for
#' downloadable tables and thus only has effect if `allow_listing_download` is
#' `TRUE`
#' @param export_label Character string with the table export label. Only used
#' for downloadable tables (if `allow_listing_download` is `TRUE`).
#' @param ... Other optional arguments that will be passed to [DT::datatable()].
#'
#' @return A `DT::datatable` object.
@@ -555,7 +554,7 @@ datatable_custom <- function(
dom = "fti",
options = list(),
allow_listing_download = NULL,
table_name = NULL,
export_label = NULL,
...
){
stopifnot(is.data.frame(data))
@@ -569,7 +568,7 @@ datatable_custom <- function(
allow_listing_download <- allow_listing_download %||%
get_golem_config("allow_listing_download")
stopifnot(is.null(allow_listing_download) | is.logical(allow_listing_download))
stopifnot(is.null(table_name) | is.character(table_name))
stopifnot(is.null(export_label) | is.character(export_label))

default_opts <- list(
scrollY = 400,
@@ -595,13 +594,13 @@ datatable_custom <- function(

# This will conditionally add a download button to the table
if(nrow(data) > 0 & isTRUE(allow_listing_download)) {
table_name <- table_name %||% "(table name missing)"
export_label <- export_label %||% "_label missing_"
extensions <- c("Buttons", extensions)
fixed_opts[["buttons"]] <- list(list(
extend = 'excel',
text = '<i class="fa-solid fa-download"></i>',
filename = paste("clinsight", table_name, sep = "."),
title = paste0(table_name, " | extracted from ClinSight")
filename = paste("clinsight", export_label, sep = "."),
title = paste0(export_label, " | extracted from ClinSight")
))
fixed_opts[["dom"]] <- paste0('B', fixed_opts[["dom"]])
}
11 changes: 6 additions & 5 deletions R/mod_common_forms.R
Original file line number Diff line number Diff line change
@@ -136,11 +136,12 @@ mod_common_forms_server <- function(
datatable_custom(
SAE_data, rename_vars = table_names, rownames= FALSE,
title = "Serious Adverse Events", escape = FALSE,
table_name = paste(
export_label = paste(
"SAE",
ifelse(input$show_all_data, "all_patients", r$subject_id),
sep = ".")
)
sep = "."
)
)
})

output[["common_form_table"]] <- DT::renderDT({
@@ -159,11 +160,11 @@ mod_common_forms_server <- function(
rownames= FALSE,
title = form,
escape = FALSE,
table_name = paste(
export_label = paste(
simplify_string(form),
ifelse(input$show_all_data, "all_patients", r$subject_id),
sep = "."
)
)
)
})

2 changes: 1 addition & 1 deletion R/mod_queries.R
Original file line number Diff line number Diff line change
@@ -158,7 +158,7 @@ mod_queries_server <- function(id, r, navinfo, all_forms, db_path, table_names){
table_names,
title = table_title,
callback = dblclick_to_form(ns("go_to_form")),
table_name = paste(ifelse(input$show_resolved, "all", "open"),
export_label = paste(ifelse(input$show_resolved, "all", "open"),
"queries", sep = ".")
)
})
5 changes: 3 additions & 2 deletions R/mod_study_forms.R
Original file line number Diff line number Diff line change
@@ -228,10 +228,11 @@ mod_study_forms_server <- function(
table_data_active(),
table_names,
escape = FALSE,
table_name = paste(
export_label = paste(
simplify_string(form),
ifelse(input$show_all, "all_patients", r$subject_id),
sep = ".")
sep = "."
)
)
})

7 changes: 3 additions & 4 deletions man/datatable_custom.Rd

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