Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
17 changes: 8 additions & 9 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,17 @@ Imports:
dplyr,
favawesome,
forcats,
ggplot2,
glue,
gsm.core (>= 1.1.5),
gsm.kri (>= 1.3.1),
gsm.vizr (>= 0.1.0),
gt (>= 1.0.0),
htmltools,
htmlwidgets,
jsonlite,
magrittr,
purrr,
rlang,
scales,
shiny (>= 1.11.1),
shinycssloaders,
shinyjs,
Expand All @@ -59,20 +58,20 @@ Suggests:
rvest,
shinytest2 (>= 0.4.1),
testthat (>= 3.0.0),
vdiffr,
withr
VignetteBuilder:
knitr
Remotes:
gsm.core=Gilead-BioStats/gsm.core@main,
gsm.kri=Gilead-BioStats/gsm.kri@main,
gsm.mapping=Gilead-BioStats/gsm.mapping@main,
gsm.reporting=Gilead-BioStats/gsm.reporting@main
Remotes:
gsm.core=Gilead-Public/gsm.core@main,
gsm.kri=Gilead-Public/gsm.kri@main,
gsm.mapping=Gilead-Public/gsm.mapping@main,
gsm.reporting=Gilead-Public/gsm.reporting@main,
gsm.vizr=Gilead-Public/gsm.vizr@main
Config/Needs/data: usethis, Gilead-BioStats/gsm.datasim@main
Config/Needs/website: gh, pkgload, readr, rmarkdown, quarto, whisker
Config/testthat/edition: 3
Encoding: UTF-8
Language: en-US
LazyData: true
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.3
Config/roxygen2/version: 8.0.0
13 changes: 11 additions & 2 deletions R/Widget_Plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ renderWidgetPlot <- function(

#' Get dependencies for a gsm widget
#'
#' Reads the widget's dependency manifest from gsm.vizr, which owns the gsm.viz
#' bundle and the shared control-lib scripts as a published runtime surface.
#' gsm.app ships its own forked widget JS and YAML; this supplies only the
#' renderer assets those forks call into.
#'
#' @inheritParams shared-params
#' @param excludes An optional vector of named dependencies to *not* include.
#'
Expand All @@ -104,7 +109,11 @@ renderWidgetPlot <- function(
#' @keywords internal
gsmDependencies <- function(strWidgetName, excludes = character()) {
gsm_dependencies <- yaml::read_yaml(
system.file("htmlwidgets", paste0(strWidgetName, ".yaml"), package = "gsm.kri")
system.file(
"htmlwidgets",
paste0(strWidgetName, ".yaml"),
package = "gsm.vizr"
)
)$dependencies
dependency_is_included <- function(dependency) {
!(dependency$name %in% excludes)
Expand All @@ -114,7 +123,7 @@ gsmDependencies <- function(strWidgetName, excludes = character()) {
gsm_dependencies,
function(dependency) {
rlang::inject({
htmltools::htmlDependency(!!!dependency, package = "gsm.kri")
htmltools::htmlDependency(!!!dependency, package = "gsm.vizr")
})
}
)
Expand Down
115 changes: 50 additions & 65 deletions R/mod_PrevalencePlot.R
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#' Plot part of the prevalence plot UI
#'
#' @inheritParams shared-params
#' @returns A [shiny::plotOutput()] object.
#' @returns A [gsm.vizr::barsOutput()] object.
#' @keywords internal
mod_PrevalencePlot_UI <- function(id) {
ns <- NS(id)
plotOutput(ns("plot"))
gsm.vizr::barsOutput(ns("plot"))
}

#' Server side of the plot part of the prevalence plot module
Expand Down Expand Up @@ -41,7 +41,7 @@ mod_PrevalencePlot_Server <- function(
PreparePrevalenceCounts(df, strCategory, chrTopValues)
})

output$plot <- renderPlot({
output$plot <- gsm.vizr::renderBars({
req(rctv_dfPrevalence())
req(rctv_strCategory())
PlotPrevalencePlot(rctv_dfPrevalence(), rctv_strCategory())
Expand Down Expand Up @@ -82,78 +82,63 @@ PreparePrevalenceCounts <- function(
.data$VizLevel,
.data$VizCategory,
fill = list(n = 0, pct = 0)
) %>%
dplyr::mutate(
fill_color = RecodeValues(
as.character(.data$VizLevel),
"Study" ~ "#1b9e77",
"Participant" ~ "#7570b3",
default = "#d95f02"
) %>%
factor()
)
}

#' Generate the prevalence ggplot
#' Build the gsm.viz bars spec for the prevalence plot
#'
#' The predecessor overlaid the three `VizLevel` series at one y position and
#' told them apart by bar width. `bars` has no per-series width control, so the
#' series would fully occlude each other under `position = "identity"`; dodge
#' carries the same comparison with position instead of width.
#'
#' @param dfPrevalence `data.frame` The prepared data.
#' @inheritParams shared-params
#'
#' @returns A [ggplot2::ggplot()].
#' @returns A [gsm.vizr::bars_spec()] list.
#' @keywords internal
PlotPrevalencePlot <- function(dfPrevalence, strCategory) {
ggplot2::ggplot(dfPrevalence) +
ggplot2::aes(
x = .data$pct,
y = .data$VizCategory,
fill = .data$fill_color,
width = 0.9 *
RecodeValues(
as.character(.data$VizLevel),
"Study" ~ 1,
"Participant" ~ 0.25,
default = 0.5
BuildPrevalenceSpec <- function(strCategory) {
gsm.vizr::bars_spec(
x = "VizCategory",
y = "pct",
fill = "VizLevel",
stat = "identity",
orientation = "horizontal",
position = "dodge",
# pct is per-VizLevel (each series already sums to 100%), so the
# stack/dodge toggle's Stack views would mix incomparable series.
interactive = FALSE,
scales = list(
x = list(label = MakeParamLabelsChr(strCategory, chrFieldNames)),
# ticks$format is currently inert: gsm.viz's getScales.js only reads a
# value-axis tick format when stat == "percent" or position == "fill",
# neither true for this dodge/identity chart. Kept as the correct,
# forward-compatible value for when gsm.viz adds support for it.
y = list(label = "% of rows", ticks = list(format = ".0%")),
fill = list(
# Dodge moves the VizLevel encoding onto colour and position, so unlike
# the width-encoded predecessor this chart needs a legend. The empty
# label keeps the legend while dropping its caption.
label = "",
colors = list(
Study = "#1b9e77",
Group = "#d95f02",
Participant = "#7570b3"
)
) +
ggplot2::geom_col(
position = "identity",
color = "black",
linewidth = ggplot2::rel(0.5)
) +
ggplot2::geom_label(
ggplot2::aes(
label = scales::label_percent(1)(.data$pct),
y = as.numeric(.data$VizCategory) +
RecodeValues(
as.character(.data$VizLevel),
"Study" ~ 0.3,
"Participant" ~ -0.3,
default = 0
)
),
x = 1.1,
color = "white",
size = 14,
size.unit = "pt",
fontface = "bold"
) +
ggplot2::scale_x_continuous(
breaks = NULL,
limits = c(0, 1.2)
) +
ggplot2::scale_fill_identity() +
theme_gsm() +
ggplot2::labs(
x = "% of rows",
y = MakeParamLabelsChr(strCategory, chrFieldNames)
) +
ggplot2::theme(legend.position = "none")
)
),
annotations = list(
labels = list(segment = list(display = TRUE, format = ".0%"))
)
)
}

#' Standard theme for gsm ggplot2 plots
#' Generate the prevalence chart
#'
#' @returns A [ggplot2::theme()].
#' @param dfPrevalence `data.frame` The prepared data.
#' @inheritParams shared-params
#'
#' @returns A [gsm.vizr::bars()] htmlwidget.
#' @keywords internal
theme_gsm <- function() {
ggplot2::theme_minimal(base_size = 20)
PlotPrevalencePlot <- function(dfPrevalence, strCategory) {
gsm.vizr::bars(dfPrevalence, BuildPrevalenceSpec(strCategory))
}
17 changes: 0 additions & 17 deletions R/utils-wrangle.R
Original file line number Diff line number Diff line change
Expand Up @@ -164,20 +164,3 @@ FindCategoricalFieldNames <- function(
chrExcludes
)
}

#' Choose between recode functions based on dplyr version
#'
#' @param x (`vector`) The vector to recode.
#' @param ... Recode pairs in the form of `old ~ new`. See [dplyr::case_match()]
#' or [dplyr::recode_values()] for details.
#' @param default (`scalar`) The default value to use for unmatched cases. See
#' [dplyr::case_match()] or [dplyr::recode_values()] for details.
#' @returns A vector with the same size as `x` with values recoded according to
#' the specified pairs and default.
#' @keywords internal
RecodeValues <- function(x, ..., default = NULL) {
if (rlang::is_installed("dplyr", version = "1.2.0")) {
return(rlang::exec(dplyr::recode_values, x, ..., default = default))
}
rlang::exec(dplyr::case_match, x, .default = default, ...) # nocov
}
21 changes: 21 additions & 0 deletions man/BuildPrevalenceSpec.Rd

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

6 changes: 3 additions & 3 deletions man/PlotPrevalencePlot.Rd

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

25 changes: 0 additions & 25 deletions man/RecodeValues.Rd

This file was deleted.

1 change: 1 addition & 0 deletions man/gsm.app-package.Rd

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

5 changes: 4 additions & 1 deletion man/gsmDependencies.Rd

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

4 changes: 2 additions & 2 deletions man/gsmWidgetOutput.Rd

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

4 changes: 2 additions & 2 deletions man/mod_ActionList_UI.Rd

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

4 changes: 2 additions & 2 deletions man/mod_DomainData_UI.Rd

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

2 changes: 1 addition & 1 deletion man/mod_DomainDetails_UI.Rd

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

Loading
Loading