Creating dynamic text inputs

Hi,

I'm currently building an app for inspecting topic models. The idea is that users can compare several models and assign topic labels, after which these labels will be used in plots etc.

I tried to solve this with dynamic text inputs:


  # Dynamically create text inputs for topic labels
  output$textInputs <- renderUI({
    w <- 1:ncol(props()) # number of topics
    uis <- vector("list", length(w))
    for (i in seq(w)) {
  
        uis[[i]] <-
          textInput(paste("TL", "0", i, sep = ""),
                    paste("Topic ", i, sep = ""),
                    value = as.character(paste0('0', w[i]))) 
    }
    uis
  })
  

This works quite well, but only as long as a user does not switch from a bigger model to a smaller one. If for instance the user switches from a model with 50 topics to a model with 30, the app breaks down:

stm_breaks

Does someone have an idea how to fix this problem?

And another question: Is it possible to place the dynamic inputs aside pairwise, such that they do not use so much vertical space?

Unfortunately I was not able to attach the corresponding shiny files, which are available here. Many thanks in advance for your help :slight_smile: