Text input to select multiple inputs one at a time


#1

Hello,

I need to take a list of input from the user. The user should be able to input the elements of the list one at a time, and they should be collected one at a time and saved in a list. I guess, the user presses enter after each input an the input box is refreshed, ready to take another input. This would be the equivalent using R code:

	while (!done) {
							cat("Type in one at a time, hit Return after each one:\n")
							i<- 1
							while (i <= length(tags)){
								x<- readline(prompt=paste("Current:",tags[i],";   NEW: "))
								if (nchar(x)==0) {
									cat("You must enter a new name.\n")
									next
								}
								new_tags[i]<- x
								i=i+1
							}
						

I know how to use the Shiny's text input component. Please see below:

 textInput("tagname", label = h4("Enter a name to designate this combined set..."), value = "Enter"),

But I do not know how to use it so that the user keeps entering names, one at a time and refreshing the input box to make it ready to take in the next input. Could you please point me to any documentation about this?

Thank you


#2

I found this code at "https://github.com/rstudio/shiny/issues/308". Please see below. I made a small change so that the textbox is not updated with the selected input but with the input entered in the box. How can I save each input in a list?

library(shiny)


ui <- fluidPage(
  headerPanel("Test"),
  
  sidebarPanel(
  #  selectInput("options", "options", choices=c('abc','def')),
    textInput("textbox", "Text", ""),
    actionButton("add","Add")
  ),
  
  mainPanel(
    textOutput("caption")
  )
)
server <- function(input, output, session) {
  observe({
    VALUE <- ''
    if(input$add>0) {
      isolate({
        VALUE <- input$textbox
      })
    }
    updateTextInput(session, inputId = "textbox", value = VALUE)
  })
  
  output$caption <- renderText({
    input$textbox
  })
}

shinyApp(ui = ui, server = server)

Thanks