Skip to content

Commit

Permalink
Refactor: let mod_datatable_server return a vector of selected conc…
Browse files Browse the repository at this point in the history
…epts instead of the entire data
  • Loading branch information
milanmlft committed Jan 23, 2025
1 parent 18120b5 commit dafaef7
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 11 deletions.
4 changes: 2 additions & 2 deletions app/R/mod_datatable.R
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ mod_datatable_ui <- function(id) {
#' @param bundle_concepts A reactive object containing the concept IDs to select as
#' an integer vector.
#'
#' @return The selected row as a reactive object
#' @return An integer vector of the selected concepts as a reactive object
#'
#' @noRd
mod_datatable_server <- function(id, selected_dates, bundle_concepts) {
Expand Down Expand Up @@ -127,7 +127,7 @@ mod_datatable_server <- function(id, selected_dates, bundle_concepts) {
DT::selectRows(datatable_proxy, selected = NULL) # nocov
})

reactive(rv$concepts_with_counts[rv$concepts_with_counts$concept_id %in% rv$selected_concepts, ])
reactive(rv$selected_concepts)
})
}

Expand Down
8 changes: 3 additions & 5 deletions app/R/mod_plots.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ mod_plots_ui <- function(id) {
#' Generates the plot of the requested `type`. When no concept is selected, or no data is available,
#' an error is raised.
#'
#' @param selected_concepts Reactive value containing the selected concepts, used for filtering
#' @param selected_concept_ids Reactive value containing the selected concept IDs, used for filtering
#' @param selected_dates Optional reactive value if date filtering needs to be applied
#'
#' @noRd
mod_plots_server <- function(id, selected_concepts, selected_dates) {
stopifnot(is.reactive(selected_concepts))
mod_plots_server <- function(id, selected_concept_ids, selected_dates) {
stopifnot(is.reactive(selected_concept_ids))
stopifnot(is.reactive(selected_dates))

## Set default theme for ggplot2
Expand All @@ -62,8 +62,6 @@ mod_plots_server <- function(id, selected_concepts, selected_dates) {


moduleServer(id, function(input, output, session) {
selected_concept_ids <- reactive(selected_concepts()$concept_id)

## Filter data based on selected concept and date range
filtered_monthly_counts <- reactive({
req(length(selected_concept_ids()) > 0)
Expand Down
8 changes: 4 additions & 4 deletions app/R/mod_select_for_export.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ mod_select_for_export_ui <- function(id) {

#' select_concepts Server Functions
#'
#' @param concepts_data A reactive data frame of concepts data
#' @param selected_concept_ids A reactive integer vector of concept IDs
#'
#' @return A reactive character vector of selected concept IDs
#'
#' @noRd
mod_select_for_export_server <- function(id, concepts_data) {
stopifnot(is.reactive(concepts_data))
mod_select_for_export_server <- function(id, selected_concept_ids) {
stopifnot(is.reactive(selected_concept_ids))

moduleServer(id, function(input, output, session) {
# Store selection in a reactiveValues object so we can update and return it later
Expand All @@ -36,7 +36,7 @@ mod_select_for_export_server <- function(id, concepts_data) {
observeEvent(input$add_to_export, {
r$current_selection <- unique(c(
r$current_selection,
concepts_data()$concept_id
selected_concept_ids()
))
})

Expand Down

0 comments on commit dafaef7

Please sign in to comment.