-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make dashboard reactive to concept selection (#31)
* Make plots reactive to the selected row in datatable * Add asserts for monthly count plot * Only show plots when row is selected * Add data getters with temporary dummy data * Add basic unit tests for datatable module * Test that concepts selection works * Use data getters in app logic * Adapt monthly_count plot to use correct column names * Test that `stat_numeric_plot` processes data correctly * Format data for numeric stats boxplot * Update docs * Ignore `.renvignore` for package builds * Add concept name as plot title for numeric stats plot * Add reactivity tests for numeric stats plot * Add reactivity tests for monthly counts module * Test monthly count plot helper * Update docs * Add note about batch processing of concepts
- Loading branch information
Showing
15 changed files
with
451 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,3 +10,4 @@ $run_dev.* | |
^LICENSE\.md$ | ||
^\.github$ | ||
^\.lintr$ | ||
^\.renvignore$ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,9 @@ Imports: | |
shiny (>= 1.9.1), | ||
DBI, | ||
duckdb, | ||
glue | ||
glue, | ||
tidyr, | ||
withr | ||
Suggests: | ||
devtools, | ||
usethis, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,34 @@ | ||
#' monthly_count_plot | ||
#' | ||
#' @description A fct function | ||
#' Generates a bar plot of the number of records per month for a given concept. | ||
#' | ||
#' @return The return value, if any, from executing the function. | ||
#' Expects the input data to have the following columns: | ||
#' - `date_year`: The year of the date. | ||
#' - `date_month`: The month of the date. | ||
#' - `person_count`: The number of records for the given month. | ||
#' | ||
#' @importFrom ggplot2 ggplot aes geom_bar ggtitle xlab ylab | ||
#' @param monthly_counts A data frame containing the monthly counts. | ||
#' @param plot_title The title for the plot. | ||
#' | ||
#' @return A ggplot2 object containing the bar plot, or `NULL` if no data is provided. | ||
#' | ||
#' @importFrom ggplot2 ggplot aes geom_bar ggtitle xlab ylab | ||
#' @noRd | ||
monthly_count_plot <- function(monthly_counts, name) { | ||
date <- record_count <- NULL | ||
ggplot(monthly_counts, aes(x = date, y = record_count)) + | ||
monthly_count_plot <- function(monthly_counts, plot_title) { | ||
stopifnot(is.data.frame(monthly_counts)) | ||
stopifnot(is.character(plot_title)) | ||
stopifnot(all(c("date_year", "date_month", "person_count") %in% colnames(monthly_counts))) | ||
|
||
monthly_counts$date <- .convert_to_date(monthly_counts$date_year, monthly_counts$date_month) | ||
|
||
date <- person_count <- NULL | ||
ggplot(monthly_counts, aes(x = date, y = person_count)) + | ||
geom_bar(stat = "identity") + | ||
ggtitle(name) + | ||
ggtitle(plot_title) + | ||
xlab("Month") + | ||
ylab("Number of records") | ||
} | ||
|
||
.convert_to_date <- function(date_year, date_month) { | ||
as.Date(paste0(date_year, "-", date_month, "-01")) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#' Get input data for the app | ||
#' | ||
#' Utility functions to retrieve the input data for the app from the database. | ||
#' | ||
#' @noRd | ||
get_concepts_table <- function() { | ||
if (golem::app_dev()) { | ||
return(data.frame( | ||
concept_id = c(40213251, 133834, 4057420), | ||
concept_name = c( | ||
"varicella virus vaccine", | ||
"Atopic dermatitis", | ||
"Catheter ablation of tissue of heart" | ||
), | ||
domain_id = c("Drug", "Condition", "Procedure"), | ||
vocabulary_id = c("CVX", "SNOMED", "SNOMED"), | ||
concept_class_id = c("CVX", "Clinical Finding", "Procedure"), | ||
standard_concept = c("S", "S", "S"), | ||
concept_code = c("21", "24079001", "18286008") | ||
)) | ||
} | ||
|
||
con <- connect_to_test_db() | ||
withr::defer(DBI::dbDisconnect(con)) | ||
DBI::dbReadTable(con, "calypso_concepts") | ||
} | ||
|
||
get_monthly_counts <- function() { | ||
if (golem::app_dev()) { | ||
return( | ||
data.frame( | ||
concept_id = c( | ||
rep(c(40213251, 133834, 4057420), each = 3) | ||
), | ||
date_year = c(2019L, 2020L, 2020L, 2019L, 2020L, 2020L, 2020L, 2019L, 2019L), | ||
date_month = c(4L, 3L, 5L, 5L, 8L, 4L, 11L, 6L, 3L), | ||
person_count = c(1, 1, 3, 4, 2, 3, 2, 4, 1), | ||
records_per_person = c(1, 1, 1, 1, 1, 1, 1, 1, 1) | ||
) | ||
) | ||
} | ||
|
||
con <- connect_to_test_db() | ||
withr::defer(DBI::dbDisconnect(con)) | ||
DBI::dbReadTable(con, "calypso_monthly_counts") | ||
} | ||
|
||
get_summary_stats <- function() { | ||
if (golem::app_dev()) { | ||
return( | ||
data.frame( | ||
concept_id = rep(c(40213251, 133834, 4057420), each = 2), | ||
summary_attribute = rep(c("mean", "sd"), times = 3), | ||
value_as_string = rep(NA, 6), | ||
value_as_number = c(1.5, 0.5, 2.5, 0.7, 3.5, 0.8) | ||
) | ||
) | ||
} | ||
|
||
con <- connect_to_test_db() | ||
withr::defer(DBI::dbDisconnect(con)) | ||
DBI::dbReadTable(con, "calypso_summary_stats") | ||
} |
Oops, something went wrong.