OK. If I'm understanding you correctly, you're saying that plugging UI elements directly into filterUI won't work, because the filter module wants to dynamically choose between different modules, depending on which tab is active. For clarity, I'm going to call the set of different modules "subfilters" rather than "tab".
First off, I think we're getting very close to the point where the subfilter modules should be nested into the filter module. That is to say,
subfilter1UI <- function(id) {...}
subfilter1 <- function(input, output, session) { ... }
subfilter2UI <- function(id) {...}
subfilter2 <- function(input, output, session) { ... }
filterUI <- function(id) {
ns <- NS(id)
uiOutput("subfilter")
}
filter <- function(input, output, session, selectedTab) {
callModule(subfilter1, "one")
callModule(subfilter2, "two")
output$subfilter <- renderUI({
req(selectedTab())
switch(selectedTab(),
"One" = subfilter1UI(session$ns("one")),
"Two" = subfilter2UI(session$ns("two"))
}
})
}
If you don't want to nest them like that, but want to still keep them separate for other reasons, then:
subfilter1UI <- function(id) {...}
subfilter1 <- function(input, output, session) { ... }
subfilter2UI <- function(id) {...}
subfilter2 <- function(input, output, session) { ... }
filterUI <- function(id) {
ns <- NS(id)
uiOutput("subfilter")
}
filter <- function(input, output, session, selectedTab, subfilters) {
callModule(subfilter1, "one")
callModule(subfilter2, "two")
output$subfilter <- renderUI({
req(selectedTab())
subfilters[[selectedTab()]]
})
}
# server function
function(input, output, session) {
callModule(subfilter1, "one")
callModule(subfilter2, "two")
callModule(filter, "filter", reactive(input$tabset),
list(
"One" = subfilter1UI("one"),
"Two" = subfilter2UI("two")
)
)
}
I'm really sorry that I can't articulate these ideas more clearly--I'd love to be able to boil this down to a simple set of rules or principles. I feel like a year from now these rules will have surfaced into my conscious mind, but right now, I'm fairly confident I can come up with the "right" solutions but have a really hard time saying what makes them right.