Skip to content
Merged
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
14 changes: 8 additions & 6 deletions R/FilterState.R
Original file line number Diff line number Diff line change
Expand Up @@ -535,11 +535,13 @@ FilterState <- R6::R6Class( # nolint
uiOutput(ns("empty"), inline = TRUE),
checkboxInput(
inputId = ns("value"),
label = countLabel(
inputId = ns("count_label"),
label = "Keep NA",
countmax = countmax,
countnow = countnow
label = tags$span(
id = ns("count_label"),
make_count_text(
label = "Keep NA",
countmax = countmax,
countnow = countnow
)
),
value = isolate(self$get_keep_na())
)
Expand All @@ -561,7 +563,7 @@ FilterState <- R6::R6Class( # nolint
# and if the reactive changes - reactive triggers only if the output is visible.
# 2. We want to trigger change of the labels only if reactive count changes (not underlying data)
output$empty <- renderUI({
updateCountLabel(
updateCountText(
inputId = "count_label",
label = "Keep NA",
countmax = private$na_count,
Expand Down
4 changes: 2 additions & 2 deletions R/FilterStateChoices.R
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ ChoicesFilterState <- R6::R6Class( # nolint
countsnow <- isolate(unname(table(factor(private$x_reactive(), levels = private$choices))))

ui_input <- if (private$is_checkboxgroup()) {
labels <- countBarLabels(
labels <- countBars(
inputId = ns("labels"),
choices = as.character(private$choices),
countsnow = countsnow,
Expand Down Expand Up @@ -271,7 +271,7 @@ ChoicesFilterState <- R6::R6Class( # nolint
private$dataname
))
if (private$is_checkboxgroup()) {
updateCountBarLabels(
updateCountBars(
inputId = "labels",
choices = as.character(private$choices),
countsmax = as.numeric(names(private$choices)),
Expand Down
4 changes: 2 additions & 2 deletions R/FilterStateLogical.R
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ LogicalFilterState <- R6::R6Class( # nolint
countsmax <- as.numeric(names(private$choices))
countsnow <- isolate(unname(table(factor(private$x_reactive(), levels = private$choices))))

labels <- countBarLabels(
labels <- countBars(
inputId = ns("labels"),
choices = as.character(private$choices),
countsnow = countsnow,
Expand Down Expand Up @@ -222,7 +222,7 @@ LogicalFilterState <- R6::R6Class( # nolint
private$varname,
private$dataname
))
updateCountBarLabels(
updateCountBars(
inputId = "labels",
choices = as.character(private$choices),
countsmax = as.numeric(names(private$choices)),
Expand Down
14 changes: 8 additions & 6 deletions R/FilterStateRange.R
Original file line number Diff line number Diff line change
Expand Up @@ -434,11 +434,13 @@ RangeFilterState <- R6::R6Class( # nolint
uiOutput(ns("empty"), inline = TRUE),
checkboxInput(
inputId = ns("value"),
label = countLabel(
inputId = ns("count_label"),
label = "Keep Inf",
countmax = countmax,
countnow = countnow
label = tags$span(
id = ns("count_label"),
make_count_text(
label = "Keep Inf",
countmax = countmax,
countnow = countnow
)
),
value = isolate(self$get_keep_inf())
)
Expand All @@ -461,7 +463,7 @@ RangeFilterState <- R6::R6Class( # nolint
# and if the reactive changes - reactive triggers only if the output is visible.
# 2. We want to trigger change of the labels only if reactive count changes (not underlying data)
output$empty <- renderUI({
updateCountLabel(
updateCountText(
inputId = "count_label",
label = "Keep Inf",
countmax = private$inf_count,
Expand Down
100 changes: 28 additions & 72 deletions R/count_labels.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#'
#' choices <- sample(as.factor(c("a", "b", "c")), size = 20, replace = TRUE)
#' counts <- table(choices)
#' labels <- countBarLabels(
#' labels <- countBars(
#' inputId = "counts",
#' choices = c("a", "b", "c"),
#' countsmax = c(20, 20, 20),
Expand All @@ -46,7 +46,7 @@
#' new_counts <- counts
#' new_counts[!names(new_counts) %in% input$choices] <- 0
#'
#' updateCountBarLabels(
#' updateCountBars(
#' inputId = "counts",
#' choices = levels(choices),
#' countsmax = c(20, 20, 20),
Expand All @@ -56,7 +56,7 @@
#' }
#' )
#' @keywords internal
countBarLabels <- function(inputId, choices, countsmax, countsnow = NULL) {
countBars <- function(inputId, choices, countsmax, countsnow = NULL) {
checkmate::assert_string(inputId)
checkmate::assert_vector(choices)
checkmate::assert_numeric(countsmax, len = length(choices))
Expand All @@ -73,7 +73,7 @@ countBarLabels <- function(inputId, choices, countsmax, countsnow = NULL) {
countmax <- countsmax[i]
countnow <- if (is.null(countsnow)) 0 else countsnow[i]

countBarLabel(
countBar(
inputId = ns(i),
label = choice,
countmax = countmax,
Expand All @@ -96,27 +96,14 @@ countBarLabels <- function(inputId, choices, countsmax, countsnow = NULL) {
#' determines `<style="width: <countmax / counttotal>%""`.
#' @return `shiny.tag` object with a progress bar and a label.
#' @keywords internal
countBarLabel <- function(inputId, label, countmax, countnow = NULL, counttotal = countmax) {
countBar <- function(inputId, label, countmax, countnow = NULL, counttotal = countmax) {
checkmate::assert_string(inputId)
checkmate::assert_string(label)
checkmate::assert_number(countmax)
checkmate::assert_number(countnow, null.ok = TRUE, upper = countmax)
checkmate::assert_number(counttotal, lower = countmax)


label_html <- countLabel(inputId = inputId, label = label, countmax = countmax, countnow = countnow)
progress_html <- countBar(inputId = inputId, countmax = countmax, countnow = countnow, counttotal = counttotal)
tags$div(progress_html, label_html)
}


#' @rdname countBarLabel
countBar <- function(inputId, countmax, countnow = NULL, counttotal) {
checkmate::assert_string(inputId)
checkmate::assert_number(countmax)
checkmate::assert_number(countnow, null.ok = TRUE)
checkmate::assert_number(counttotal)

label <- make_count_text(label, countmax = countmax, countnow = countnow)
ns <- NS(inputId)
tags$div(
class = "progress state-count-container",
Expand All @@ -125,7 +112,8 @@ countBar <- function(inputId, countmax, countnow = NULL, counttotal) {
id = ns("count_bar_filtered"),
class = "progress-bar state-count-bar-filtered",
style = sprintf("width: %s%%", countnow / counttotal * 100),
role = "progressbar"
role = "progressbar",
label
),
tags$div(
id = ns("count_bar_unfiltered"),
Expand All @@ -136,20 +124,8 @@ countBar <- function(inputId, countmax, countnow = NULL, counttotal) {
)
}

#' @rdname countBarLabel
countLabel <- function(inputId, label, countmax, countnow = NULL) {
checkmate::assert_string(inputId)
checkmate::assert_string(label)
checkmate::assert_number(countmax)
checkmate::assert_number(countnow, null.ok = TRUE)

ns <- NS(inputId)
label <- make_count_text(label = label, countmax = countmax, countnow = countnow)
label_html <- tags$div(id = ns("count_text"), class = "state-count-text", label)
}

#' @rdname countBarLabels
updateCountBarLabels <- function(session = getDefaultReactiveDomain(), inputId, choices,
#' @rdname countBars
updateCountBars <- function(session = getDefaultReactiveDomain(), inputId, choices,
countsmax, countsnow = NULL) {
checkmate::assert_string(inputId)
checkmate::assert_vector(choices)
Expand All @@ -162,14 +138,9 @@ updateCountBarLabels <- function(session = getDefaultReactiveDomain(), inputId,
choice <- choices[i]
countmax <- countsmax[i]
countnow <- if (is.null(countsnow)) countmax else countsnow[i]
updateCountLabel(
inputId = ns(i),
label = choice,
countmax = countmax,
countnow = countnow
)
updateCountBar(
inputId = ns(i),
label = choice,
countmax = countmax,
countnow = countnow,
counttotal = counttotal
Expand All @@ -178,61 +149,46 @@ updateCountBarLabels <- function(session = getDefaultReactiveDomain(), inputId,
invisible(NULL)
}

#' @rdname countBarLabel
updateCountBarLabel <- function(session = getDefaultReactiveDomain(), inputId, label,
#' @rdname countBar
updateCountBar <- function(session = getDefaultReactiveDomain(), inputId, label,
countmax, countnow = NULL, counttotal) {
checkmate::assert_string(inputId)
checkmate::assert_string(label)
checkmate::assert_number(countmax)
checkmate::assert_number(countnow, null.ok = TRUE)
checkmate::assert_number(counttotal)

label <- make_count_label(label, countmax = countmax, countnow = countnow)
if (is.null(countnow)) countnow <- countmax

updateCountLabel(inputId = inputId, label = label, countmax = countmax, countnow = countnow)
updateCountBar(inputId = inputId, countmax = countmax, countnow = countnow, counttotal = counttotal)

invisible(NULL)
}

#' @rdname countBarLabel
updateCountLabel <- function(session = getDefaultReactiveDomain(), inputId, label, countmax, countnow) {
checkmate::assert_string(inputId)
checkmate::assert_string(label)
checkmate::assert_number(countmax)
checkmate::assert_number(countnow, null.ok = TRUE)

label <- make_count_text(label = label, countmax = countmax, countnow = countnow)

label <- make_count_text(label, countmax = countmax, countnow = countnow)
session$sendCustomMessage(
type = "updateCountLabel",
type = "updateCountBar",
message = list(
id = session$ns(inputId),
label = label
label = label,
countmax = countmax,
countnow = countnow,
counttotal = counttotal
)
)

invisible(NULL)
}

#' @rdname countBarLabel
updateCountBar <- function(session = getDefaultReactiveDomain(), inputId, countmax, countnow, counttotal) {
updateCountText <- function(session = getDefaultReactiveDomain(), inputId, label, countmax, countnow) {
checkmate::assert_string(inputId)
checkmate::assert_string(label)
checkmate::assert_number(countmax)
checkmate::assert_number(countnow, null.ok = TRUE)
checkmate::assert_number(counttotal)

label <- make_count_text(label, countmax = countmax, countnow = countnow)
session$sendCustomMessage(
type = "updateCountBar",
type = "updateCountText",
message = list(
id = session$ns(inputId),
countmax = countmax,
countnow = countnow,
counttotal = counttotal
label = label
)
)
)
}


#' Make a count text
#'
#' Returns a text describing filtered counts. Text is composed in following way:
Expand All @@ -253,4 +209,4 @@ make_count_text <- function(label, countmax, countnow = NULL) {
if (is.null(countnow)) "" else sprintf("%s/", countnow),
countmax
)
}
}
9 changes: 8 additions & 1 deletion inst/css/filter-panel.css
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,8 @@ a.remove_all:hover {
.state-count-container {
height: 1.75em;
width: 90%;
position: absolute;
background-color: white;
margin: 0px;
}

.state-count-bar-filtered {
Expand All @@ -271,3 +271,10 @@ a.remove_all:hover {
position: absolute;
width: 100%;
}

.progress-bar.state-count-bar-filtered {
color: var(--bs-body-color, var(--dark, #333333));
overflow: visible;
text-align: left;
white-space: nowrap;
}
8 changes: 4 additions & 4 deletions inst/js/count-bar-labels.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ Shiny.addCustomMessageHandler("updateCountBar",

bar1.style.width = message.countnow / message.counttotal * 100 + "%";
bar2.style.width = (message.countmax - message.countnow) / message.counttotal * 100 + "%";
bar1.textContent = message.label;
}
);

Shiny.addCustomMessageHandler("updateCountLabel",
Shiny.addCustomMessageHandler("updateCountText",
function(message) {
/* updates Text */
let e1 = document.getElementById(message.id + "-count_text");
e1.textContent = message.label;
let el = document.getElementById(message.id)
el.textContent = message.label
}
);
10 changes: 5 additions & 5 deletions man/countBarLabel.Rd

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

14 changes: 7 additions & 7 deletions man/countBarLabels.Rd

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

Loading