Skip to content

Commit

Permalink
Return row IDs as well
Browse files Browse the repository at this point in the history
  • Loading branch information
jthompson-arcus committed Dec 10, 2024
1 parent 5c64e08 commit 02e65df
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 9 deletions.
6 changes: 4 additions & 2 deletions R/fct_tables.R
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ create_table.default <- function(
names_from = {{name_column}},
values_from = {{value_column}},
values_fn = ~paste0(., collapse = "; ")
)
)
if ("o_reviewed" %in% names(df))
df <- dplyr::mutate(df, o_reviewed = lapply(dplyr::row_number(), \(x) append(o_reviewed[[x]], list(row_id = x))))
expected_columns <- na.omit(expected_columns) %||% character(0)
if(length(expected_columns) == 0) return(df)
add_missing_columns(df, expected_columns)[
Expand Down Expand Up @@ -238,7 +240,7 @@ create_table.adverse_events <- function(
keep_vars, expected_columns) |>
adjust_colnames("^AE ")
df[["Number"]] <- NULL

# create new row when an AE gets worse:
df_worsening <- df[!is.na(df[[worsening_start_column]]), ] |>
dplyr::mutate(
Expand Down
4 changes: 2 additions & 2 deletions R/mod_common_forms.R
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ mod_common_forms_server <- function(
session$userData$review_records[[form]] <-
dplyr::rows_upsert(
session$userData$review_records[[form]],
input$common_form_table_review_selection,
input$common_form_table_review_selection[c("id", "reviewed")],
by = "id"
) |>
dplyr::filter(!is.na(reviewed)) |>
Expand Down Expand Up @@ -189,7 +189,7 @@ mod_common_forms_server <- function(
session$userData$review_records[[form]] <-
dplyr::rows_upsert(
session$userData$review_records[[form]],
input$SAE_table_review_selection,
input$SAE_table_review_selection[c("id", "reviewed")],
by = "id"
) |>
dplyr::filter(!is.na(reviewed)) |>
Expand Down
2 changes: 1 addition & 1 deletion R/mod_study_forms.R
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ mod_study_forms_server <- function(
session$userData$review_records[[form]] <-
dplyr::rows_upsert(
session$userData$review_records[[form]],
input$table_review_selection,
input$table_review_selection[, c("id", "reviewed")],
by = "id"
) |>
dplyr::filter(!is.na(reviewed)) |>
Expand Down
7 changes: 3 additions & 4 deletions R/shiny.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
shiny::registerInputHandler('CS.reviewInfo', function(val, ...) {
with(val, data.frame(
id = unlist(ids),
reviewed = ifelse(isTRUE(review), "Yes", ifelse(isFALSE(review), "No", NA_character_))
reviewed = ifelse(isTRUE(review), "Yes", ifelse(isFALSE(review), "No", NA_character_)),
row_id = row_id
))
}, TRUE)

Expand All @@ -19,11 +20,9 @@ checkbox_callback <- DT::JS(
"table.on('click', 'input[type=\"checkbox\"]', function(){",
"var tblId = $(this).closest('.datatables').attr('id');",
"var cell = table.cell($(this).closest('td'));",
"var rowIdx = table.row($(this).closest('tr')).index();",
"var ids = cell.data().ids;",
"var review = $(this).is(':indeterminate') ? null : $(this).is(':checked');",
"cell.data().updated = review;",
"var info = {review: review, ids: ids, row: tblId + '_row_' + rowIdx};",
"var info = {review: review, ids: cell.data().ids, row_id: cell.data().row_id};",
"Shiny.setInputValue(tblId + '_review_selection:CS.reviewInfo', info);",
"});"
)
Expand Down

0 comments on commit 02e65df

Please sign in to comment.