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
Next Next commit
Use the adjusted datatable_cusom in all modules
LDSamson committed Jan 10, 2025
commit 906a0443ad11072e0d7d088d5504fa4e82251d71
29 changes: 0 additions & 29 deletions R/fct_data_helpers.R
Original file line number Diff line number Diff line change
@@ -505,35 +505,6 @@ 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
28 changes: 16 additions & 12 deletions R/mod_common_forms.R
Original file line number Diff line number Diff line change
@@ -133,15 +133,14 @@ mod_common_forms_server <- function(
adjust_colnames("^SAE ")
if(!input$show_all_data) SAE_data$subject_id <- NULL

# 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
)
table_name = paste(
"SAE",
ifelse(input$show_all_data, "all_patients", r$subject_id),
sep = ".")
)
})

output[["common_form_table"]] <- DT::renderDT({
@@ -154,13 +153,18 @@ mod_common_forms_server <- function(
}
if(!input$show_all_data) df$subject_id <- NULL

# 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)
df,
rename_vars = table_names,
rownames= FALSE,
title = form,
escape = FALSE,
table_name = paste(
simplify_string(form),
ifelse(input$show_all_data, "all_patients", simplify_string(r$subject_id)),
sep = "."
)
)
})

})
6 changes: 4 additions & 2 deletions R/mod_navigate_review.R
Original file line number Diff line number Diff line change
@@ -130,7 +130,8 @@ mod_navigate_review_server <- function(
df[["reviewed"]] <- NULL
if(!input$show_all_data) df$subject_id <- NULL
datatable_custom(df, table_names,
callback = dblclick_to_form(ns("go_to_form")))
callback = dblclick_to_form(ns("go_to_form")),
allow_listing_download = FALSE)
})

queries_table_data <- reactive({
@@ -158,7 +159,8 @@ mod_navigate_review_server <- function(
pageLength = -1
),
rownames = FALSE,
selection = "none"
selection = "none",
allow_listing_download = FALSE
)
})

11 changes: 6 additions & 5 deletions R/mod_queries.R
Original file line number Diff line number Diff line change
@@ -151,15 +151,15 @@ mod_queries_server <- function(id, r, navinfo, all_forms, db_path, table_names){
}

# 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")),
dom = DT$dom, extensions = DT$exts, options = DT$opts
table_name = paste(ifelse(input$show_resolved, "all", "open"),
"queries", sep = ".")
)
})

@@ -190,7 +190,8 @@ mod_queries_server <- function(id, r, navinfo, all_forms, db_path, table_names){
),
class = "row-border hover",
rownames = FALSE,
selection = "none"
selection = "none",
allow_listing_download = FALSE
)
})
})
6 changes: 4 additions & 2 deletions R/mod_report.R
Original file line number Diff line number Diff line change
@@ -187,12 +187,14 @@ mod_report_server <- function(id, r, rev_data, db_path, table_names){
})

output[["review_completed_table"]] <- DT::renderDT({
datatable_custom(selected_review_data(), table_names, rownames = FALSE)
datatable_custom(selected_review_data(), table_names, rownames = FALSE,
allow_listing_download = FALSE)
})

output[["queries_raised_table"]] <- DT::renderDT({
req(query_data())
datatable_custom(selected_query_data()[, -1], table_names, rownames = FALSE)
datatable_custom(selected_query_data()[, -1], table_names, rownames = FALSE,
allow_listing_download = FALSE)
})

output[["report"]] <- downloadHandler(
3 changes: 2 additions & 1 deletion R/mod_start_page.R
Original file line number Diff line number Diff line change
@@ -87,7 +87,8 @@ mod_start_page_server <- function(id, r, rev_data, navinfo, all_forms, table_nam
tab <- datatable_custom(
dplyr::select(rev_data$overview(), -needs_review),
rename_vars = table_names,
callback = dblclick_to_form(ns("go_to_patient"))
callback = dblclick_to_form(ns("go_to_patient")),
allow_listing_download = FALSE
)
if(length(bold_rows) == 0) return(tab)
DT::formatStyle(
16 changes: 10 additions & 6 deletions R/mod_study_forms.R
Original file line number Diff line number Diff line change
@@ -223,12 +223,16 @@ mod_study_forms_server <- function(

output[["table"]] <- DT::renderDT({
req(table_data_active())
# 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)

datatable_custom(
table_data_active(),
table_names,
escape = FALSE,
table_name = paste(
simplify_string(form),
ifelse(input$show_all, "all_patients", r$subject_id),
sep = ".")
)
})

if(form %in% c("Vital signs", "Vitals adjusted")){
23 changes: 0 additions & 23 deletions man/dt_config.Rd

This file was deleted.