I want to write a module with a dynamic number n, say, of UI elements. I observed that the input slot does not correspond with current number of elements but the largest number chosen during the session:
library(shiny) library(plyr) testUI <- function(id) { ns <- NS(id) uiOutput(ns("container")) } test <- function(input, output, session, numElems) { output$container <- renderUI(do.call(tagList, llply(1:numElems(), function(i) selectInput(session$ns(paste0("elem", i)), label = i, choices = LETTERS[sample(26, 3)])))) getNames <- reactive(reactiveValuesToList(input)) list(getNames = getNames) } ui <- fluidPage(numericInput("n", "Number of Elems", value = 3), testUI("column1"), verbatimTextOutput("debug")) server <- function(input, output, session) { getN <- reactive(input$n) handler <- callModule(test, "column1", getN) output$debug <- renderPrint(handler$getNames()) } shinyApp(ui, server) If you change the number of elements in the numeric input field from 3 to 2, we see that there are still 3 elements in input. Is this behaviour intentional? If so, how can I update the input to asure that it only contains valid slots?
Update
Here are the 2 relevant screenshots:


0 comments:
Post a Comment