insightsengineering / insightsengineering/teal

allow module to ignore filter panel

Open
#905 12 comments 0 reactions 1 assignee Claimed by @gogonzo View on GitHub
core discussion
Dominant language
R
Stars
263
Forks
59
Avg merge
5d 17h
Merged PRs (30d)
5

Description

The `datanames` argument in `modules` can cause the filter panel to not be displayed in a module, which means no filters can be added for that module. However, global filters are applied to **all** modules, including ones do not display the filter panel ("funny1" and "empty") and ones that take no data at all ("empty").

![filters](https://github.com/insightsengineering/teal/assets/114988527/e772a54a-9a3b-4b7b-8103-be301feede5e)

Should we allow an app dev to run an application in which selected modules are exempt from filtering?

My feeling is that data-less modules should show up as "n/a" in the filter manager at least but I believe it should not be done by patching the display. Rather, we should have a way for `teal` to make `FilteredData` inert.

Please discuss.

### modules
```
library(teal.modules.general)
pkgload::load_all("../teal.slice")
pkgload::load_all("../teal")

rm(list = ls())

funny_module <- function (label = "Filter states", datanames = "all") {
checkmate::assert_string(label)
module(
label = label,
datanames = datanames,
ui = function(id, ...) {
ns <- NS(id)
div(
h2("The following filter calls are generated:"),
verbatimTextOutput(ns("filter_states")),
verbatimTextOutput(ns("filter_calls")),
actionButton(ns("reset"), "reset_to_default")
)
},
server = function(input, output, session, data, filter_panel_api) {
checkmate::assert_class(data, "tdata")
observeEvent(input$reset, set_filter_state(filter_panel_api, default_filters))
output$filter_states <- renderPrint({
logger::log_trace("rendering text1")
filter_panel_api %>% get_filter_state()
})
output$filter_calls <- renderText({
logger::log_trace("rendering text2")
attr(data, "code")()
})
}
)
}

dead_module <- function(label = "empty module", datanames = NULL) {
module(label = label,
datanames = datanames,
ui = function(id) {
ns <- NS(id)
tagList(
h4("this is just text")
)
},
server = function(id, filter_panel_api) {
message("hello")
}
)
}
```

### filters
```
default_filters <- teal::teal_slices(
teal_slice("iris", "Sepal.Length"),
teal_slice("iris", "Sepal.Width"),
teal_slice("iris", "Species"),
teal_slice("mtcars", "mpg"),
exclude_varnames = list(
iris = c("Petal.Length"),
mtcars = c("qsec", "drat")
),
module_specific = TRUE,
mapping = list(
funny1 = c("iris Sepal.Length", "iris Sepal.Width", "iris Species"),
funny2 = "iris Species",
global_filters = "mtcars mpg"
)
)
```

# app
```
app <- init(
data = teal_data(
dataset("iris", iris),
dataset("mtcars", mtcars)
),
modules = modules(
tm_data_table(
"table",
variables_selected = list(),
dt_args = list()
),
modules(
label = "tab1",
funny_module("funny1", datanames = NULL),
funny_module("funny2", datanames = "iris"),
dead_module(datanames = NULL)
)
), filter = default_filters
)

runApp(app, launch.browser = TRUE)
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.