Not possible to retrieve module's session using `getDefaultReactiveDomain()`?
I'm not sure if this should be considered a bug or a feature request or perhaps neither.
I expected that using getDefaultReactiveDomain() from inside a module would always a session object that can properly namespace the current module. But that doesn't seem to be the case when the call is being invoked from outside the module.
Consider this code:
library(shiny)
testmod_UI <- function(id) {}
testmod <- function(input, output, session) {
print_ns <- function() {
print(session$ns(""))
print(getDefaultReactiveDomain()$ns(""))
}
return(print_ns)
}
ui <- fluidPage(
testmod_UI("foo"),
actionButton("btn", "btn")
)
server <- function(input, output, session) {
test <- callModule(testmod, "foo")
observeEvent(input$btn, {
test()
})
}
shinyApp(ui, server)
It simply prints the session's namespace twice, once using the server's session object and once using the result of getDefaultReactiveDomain(). Because the function call is technically made outside the module, the second one doesn't return the module's namespace.
Perhaps this is the correct behaviour according to how environments work, but I feel that there should be a way to retrieve the module server's session. This is a small contrived example, but in my real use case I have a function outside of the module that builds an input given an ID. It attempts to retrieve the session object so that it can automatically detect the namespace, if any. I can work around this of course, but I wanted to get your thoughts on whether this is something that should be supported or not.
This is still a bug - can anyone in shiny team see if this is an easy fix?