Skip to content

filter_data_server 'vars' = reactive(NULL) can't be used #121

Description

@gitdemont

Dear datamods author,

I think it could be usefull to change the behaviour of reactive(NULL) for vars.
Indeed, when looking at the code filter_data_server will call create_filter to build the appropriate ui elements required for filtering data.
Default behaviour is to build filters for all data columns due to those lines since default vars argument value of filter_data_server is reactive(NULL) and NULL is 'corrected' to names(data).
For me this default behaviour is sane (if user did not pass value to vars ones may want to populate ui with all filters initially). However, I think it should be triggered by vars = reactive(names(data())) so as to liberate the use of reactive(NULL)

In my use case, vars is bound to a selectInput(...,multiple = TRUE) so that I can populate ui with the filters I only need.
Unfortunately, absence of selection send NULL which results in selecting everything which is kind of misleading/irrational

So, in create_filter, I would apply thoses changes to code:

if (!is.null(vars)) {
  if (rlang::is_named(vars)) {
    labels <- names(vars)
    vars <- unname(unlist(vars))
  } else {
    labels <- vars
  }
  vars_display <- intersect(vars, names(data))
  labels <- labels[vars %in% vars_display]
  vars <- vars_display
  # filters_id <- paste0("filter_", sample.int(1e9, length(vars)))
  filters_id <- paste0("filter_", makeId(vars))
  filters_id <- setNames(as.list(filters_id), vars)
  filters_na_id <- setNames(as.list(paste0("na_", filters_id)), vars)
}

And in filter_data_server, this one to code

vars = reactive(names(data())

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions