Another Little Shiny Module Trick

Probably everyone knows this but me, but I wanted to use the namespace in my Shiny server module function and I finally figured out how to accomplish this in a non-hacky way.  So in continuation of my unplanned Shiny module tips (see Super Simple Shiny Modules), here is the code.

library(shiny)

moduleUI <- function(id) {
  ns <- NS(id)
  div(sprintf("hi from %s", ns(NULL)))
}
module <- function(input, output, session) {
  print(session$ns(NULL))
}

ui <- div(
  h3("module"),
  moduleUI("module")
)
server <- function(...) {
  callModule(module, "module")
}
shinyApp(ui,server)