Skip to content

Commit

Permalink
handle missing selectors
Browse files Browse the repository at this point in the history
  • Loading branch information
gogonzo committed Jan 3, 2023
1 parent 35c4625 commit 5a9b14f
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions R/tm_g_barchart_simple.R
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,10 @@ srv_g_barchart_simple <- function(id,
shiny::moduleServer(id, function(input, output, session) {
rule_dupl <- function(others) {
function(value) {
othervals <- lapply(others, function(x) selector_list()[[x]]()$select)
othervals <- lapply(
Filter(Negate(is.null), selector_list()[others]), # some selectors could be ommited in tm_g_barchart_simple
function(x) x()$select
)
vars <- c(value, unlist(othervals))
dups <- unique(vars[duplicated(vars)])
if (value %in% dups) {
Expand Down Expand Up @@ -461,10 +464,10 @@ srv_g_barchart_simple <- function(id,

plot_call <- make_barchart_simple_call(
y_name = get_n_name(groupby_vars),
x_name = groupby_vars$x_name,
fill_name = groupby_vars$fill_name,
x_facet_name = groupby_vars$x_facet_name,
y_facet_name = groupby_vars$y_facet_name,
x_name = groupby_vars$x,
fill_name = groupby_vars$fill,
x_facet_name = groupby_vars$x_facet,
y_facet_name = groupby_vars$y_facet,
label_bars = input$label_bars,
barlayout = input$barlayout,
flip_axis = input$flip_axis,
Expand Down Expand Up @@ -492,17 +495,15 @@ srv_g_barchart_simple <- function(id,
# get grouping variables
# NULL: not present in UI, vs character(0): no selection
## helper function

This comment has been minimized.

Copy link
@chlebowa

chlebowa Jan 3, 2023

Contributor

this comment line can go now

resolve_argument <- function(x) {
ans <- if (is.null(x)) NULL else selector_list()[[deparse(substitute(x))]]()$select
if (identical(ans, character(0L))) NULL else ans
}
## returns named vector of non-NULL variables to group by
r_groupby_vars <- function() {
c(
x_name = resolve_argument(x),
fill_name = resolve_argument(fill),
x_facet_name = resolve_argument(x_facet),
y_facet_name = resolve_argument(y_facet)
unlist(
lapply(
selector_list(),
function(selector) {
if (is.null(selector)) character(0L) else selector()$select
}
)
)
}

Expand Down

0 comments on commit 5a9b14f

Please sign in to comment.