Passing a reactive value into a called module

Solution 1:

The input parameter should be sent as reactive, for that just use reactive(input$message). Since now message_text is a reactive value, you need to use it as message_text().

library(shiny)

## create module to print text - not that UI selector must be rendered 
## from server as this is behavior in real app
textUI <- function(id) {
  uiOutput(NS(id, "UI"))
}

textServer <- function(id, message_text) {
  moduleServer(id, function(input, output, session) {
    output$UI <- renderUI({
      textOutput(outputId = NS(id, "text"))
    })
    output$text <- renderText(expr = message_text())
  })
}

## call module components
ui <- fluidPage(
  selectInput(inputId = "message", 
              label = "Text Display", 
              choices = c("a", "b")),
  textUI(id = "test")
)

server <- function(input, output, session) {
  textServer(id = "test", 
             message_text = reactive(input$message))
}

shinyApp(ui, server)