1

I have a uiOutput that is dependent on what option the user selects but this does not display when I run the app.

Please see an extract of the app below.

text_analytics_UI <- function(id, label = "Name") {
  ns <- NS(id)
  tagList(
    useShinyjs(),
    fluidRow(
      
                 radioButtons("typeRadio", "Choose filter type", 
                              choices = list("Keyword search" = "keyword", "Browse sectors" = "sectors")),
                 uiOutput(ns("searchControls")),
                 ))}


Module Server

text_analytics_server <- function(id, Project_ID, User) {
  moduleServer(id,
               function(input, output, session) {
                 message("Module ", id, " has been activated!")
                 module <- reactiveValues()
                 ns <- NS(id)
                 useShinyjs()

set which search controls appear

 output$searchControls <- renderUI({
                   if(input$typeRadio == "keyword") {
                     tagList(
                       textInput("searchterm", "Enter your keyword here", value = "", placeholder = "Leave empty to show general insights")
                     )
                   }
                   else {
                     tagList(
                       selectInput('sectors', 'Filter Sectors', 
                                   choices = unique(copy_responses_table$sector)),
                       selectInput('bodies', 'Filter Bodies', 
                                   choices = unique(copy_responses_table$name), multiple = T)
                     )
                   }
                   
                 })

When I run the app with my current code, the radioButtons display but nothing happens when I toggle between this options.

The logic works normally as an independent app but not when encoded as a module. I suspect this has to do with namespaces.

Oyeleke
  • 13
  • 2
  • I think you should use `ns()` for the id of radiobutton as well like what you did for uiOutput(ns("searchControls")). something like this: ns("typeRadio") – Alihdr Mar 02 '23 at 15:32
  • Sounds good, I add this as an answer for other users. you may accept it as a correct answer ;) – Alihdr Mar 02 '23 at 16:14

1 Answers1

0

In the text_analytics_UI part, the id of radiobutton should be inside on ns() function.

text_analytics_UI <- function(id, label = "Name") {
  ns <- NS(id)
  tagList(
    useShinyjs(),
    fluidRow(
      
                 radioButtons(ns("typeRadio"), "Choose filter type", 
                              choices = list("Keyword search" = "keyword", "Browse sectors" = "sectors")),
                 uiOutput(ns("searchControls")),
                 ))}
Alihdr
  • 241
  • 2
  • 9