Iterative GUI display

Hello,

Is there a way to display UI iteratively with user input? Below is the idea.

ui <- fluidPage(
selectInput("something", ..............)
verbatimTextOutput("thing")
)

server <- function(input, output){

output$thing <- renderPrint({
  shinyjs::show("something")
)}
while(length(input$something) == 1){
   shinyjs::show("something)
}
}

I have tried the code below and it works, but I cannot implement the same thing using a while loop.

ui <- fluidPage(

hidden(selectInput("filescombinemessage",label = h5(strong("Must select more than one data set. Try again.. To undo selection select the selected file again and press delete")),c(Choose='', list.files("~/Development/fileTest/folder3/DATA")), multiple=TRUE, selectize=TRUE)),

)
  values <- reactiveValues(n = 0)
  observeEvent(input$filescombinemessage,{
    values$n <- length(input$filescombinemessage)
  })
  
  output$onlyOneSelected<- renderPrint({
    
    if(!is.null(values$n)){
      if(values$n == 1){
        shinyjs::show("filescombinemessage")
      }else{
        shinyjs::hide("filescombinemessage")
      }
    }
  })

This is with the implementation of a while loop

server<- function(input, output){
  values <- reactiveValues(n = 0)
  observeEvent(input$filescombine,{
    values$n <- length(input$filescombine)
  })
  
  output$onlyOneSelected<- renderPrint({
    
    if(!is.null(values$n)){
      while(values$n == 1){
        shinyjs::show("filescombinemessage")
      }
    }
  })
}

The implementation with the loop does not work. I would like for the message to keep displaying as long as the user selects one item only

What is the need for the while loop? If it works with just the simple if/else statement, then I am not understanding the need to complicate it with a while loop.

In addition, you may want to look at the shinyalert package, as they implement what you seem to be trying to do very nicely, without having to worry about switching between hidden and showing a ui element. In addition, it is written by the same author as shinyjs so it follows a somewhat similar implementation process, although more straightforward for this use case, in my opinion.

Thanks very much for your info.