Skip to content

Commit

Permalink
require ratio_lab when ratio_var provided
Browse files Browse the repository at this point in the history
also removed leaflet.extras dependency
  • Loading branch information
PaulC91 committed Nov 15, 2023
1 parent 5b6c14d commit 06ff341
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ RoxygenNote: 7.2.3
Imports:
shiny (>= 1.5.0),
bslib (>= 0.5.1),
bsicons,
shinyWidgets,
htmltools,
htmlwidgets,
Expand All @@ -38,7 +39,6 @@ Imports:
gtsummary,
sf,
leaflet,
leaflet.extras,
leaflet.minicharts,
chromote,
mapview,
Expand Down
15 changes: 10 additions & 5 deletions R/01_time.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
#' @rdname time
#'
#' @param id Module id. Must be the same in both the UI and server function to link the two.
#' @param date_vars named character vector of date variables for the date axis input. Names are used as variable labels.
#' @param date_vars Character vector of date variable(s) for the date axis. If named, names are used as variable labels.
#' @param group_vars Character vector of categorical variable names. If provided, a select input will appear
#' in the options dropdown allowing for data groups to be visualised as stacked bars on the epicurve.
#' If named, names are used as variable labels.
#' @param title header title for the card.
#' @param title Header title for the card.
#' @param icon The icon to display next to the title.
#' @param opts_btn_lab text label for the dropdown menu button.
#' @param date_lab text label for the date variable input.
Expand Down Expand Up @@ -208,8 +208,13 @@ time_server <- function(
}

if (!is.null(ratio_var)) {
if (is.null(ratio_numer) || is.null(ratio_denom)) {
stop("both `ratio_numer` and `ratio_denom` must be supplied when `ratio_var` is supplied")
if (any(is.null(ratio_numer), is.null(ratio_denom), is.null(ratio_lab))) {
cli::cli_abort(c(
"x" = "when `ratio_var` is supplied, you must provide the following accompanying arguments:",
"*" = "ratio_numer`: character vector of ratio calculation numerator value(s)",
"*" = "ratio_denom`: character vector of ratio calculation denominator value(s)",
"*" = "ratio_lab`: the axis label to be used for the ratio line"
))
}

df_ratio <- df_mod() %>%
Expand All @@ -221,7 +226,7 @@ time_server <- function(
dplyr::group_by(!!date) %>%
dplyr::summarise(
n1 = sum(.data[[ratio_var]] %in% ratio_numer),
N = sum(.data[[ratio_var]] %in% ratio_denom),
N = sum(.data[[ratio_var]] %in% unique(c(ratio_numer, ratio_denom))),
ratio = (.data$n1 / .data$N) * 100,
.groups = "drop"
) %>%
Expand Down
1 change: 0 additions & 1 deletion R/02_place.R
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,6 @@ place_server <- function(
names(var_list[var_list == map_var])
)


# save as reactive values
rv$geo_join <- geo_join
rv$join_cols <- join_cols
Expand Down
1 change: 0 additions & 1 deletion R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,6 @@ leaf_basemap <- function(
position = "bottomright",
options = leaflet::scaleBarOptions(imperial = FALSE)
) %>%
leaflet.extras::addResetMapButton() %>%
leaflet::addLayersControl(
baseGroups = baseGroups,
overlayGroups = overlayGroups,
Expand Down

0 comments on commit 06ff341

Please sign in to comment.