Shiny modules namespace outside of UI for javascript links
<p>I am trying to use shiny modules to re-use the UI and server code to present off of three different data sets that share the same presentation.</p>

<p>Running into a bit of a challenge dealing with namespace when using javascript based modal popup link creation outside of the UI / server code.</p>

<p>Here is my non-working app code:</p>

<pre><code>library(shiny)
library(shinyBS)
library(DT)

df &lt;- data.frame(id = c('a', 'b', 'c'), value = c(1, 2, 3))

on_click_js = "
Shiny.onInputChange('myLinkName', '%s');
$('#myModal').modal('show')
"

convert_to_link = function(x) {
  as.character(tags$a(href = "#", onclick = sprintf(on_click_js, x), x))
}
df$id_linked &lt;- sapply(df$id, convert_to_link)
df &lt;- df[, c('id_linked', 'value')]

mySampleUI &lt;- function(id) {
  ns &lt;- NS(id)

  fluidPage(
    mainPanel(
      dataTableOutput(ns('myDT')),
      bsModal(id = 'myModal',
              title = 'My Modal Title',
              trigger = '',
              size = 'large',
              textOutput(ns('modalDescription'))
      ),
      width = 12
    )
  )
}

ui &lt;- fluidPage(mySampleUI('myUI'))

myServerFunc &lt;- function(input, output, session, df) {
  output$myDT &lt;- DT::renderDataTable({
    datatable(df, escape = FALSE, selection='none')
  })
  output$modalDescription &lt;- renderText({
    sprintf('My beautiful %s', input$myLinkName)
  })
}

server &lt;- function(input, output) {
  callModule(myServerFunc, 'myUI', df)
}

shinyApp(ui = ui, server = server)
</code></pre>

<p>A working version would successfully display <code>myLinkName</code> in the description portion of the modal pop up. The reason this code does not work is because the UI component ID value is created outside of the UI code without the namespace containment. I get that. But, I am not able to figure out how to re-work it so that the name space matches.</p>

<p>Any ideas / options?</p>