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")),
))}
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()
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.
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")),
))}