Why does textInput instantly disappear in r shiny?

I'm trying to have the user enter text into a number of textboxes equal to an earlier input. So I need to put it in a renderUI block. I did this but when I try to type into the input box the new text will only stay for half a second and then it will disappear and the original default text will replace it. I did post some of the code, but the actual program is much larger so I didn't want to post all of it. Thanks for any help.


#User interface
ui <- fluidPage(
    #Number of treatments input
                 "Enter number of treatments:", min =
                     1, 3),
    #Number of outcomes input
    numericInput("numoc", "Enter number of outcomes:", min =
                     1, 3),

server <- function(input, output) {
    option_vector <- c()
    output$oc_names <- renderUI({
        k = rep(c(1:input$numoc), times = input$inp1)
        for (g in 1:input$numoc) {
            option_vector <- append(option_vector, g)
        mylist3 <-
            lapply(1:(input$numoc), function(i, y = k[[i]]) {
                pref_identifier <- paste("rank", i, sep = "")
                outcome_id <- paste("ocrank", i, sep = "")
                if (i == 1) {
                    pref_name <- paste("Outcome #", y, sep = "")
                } else {
                    width = 3,
                    textInput(inputId = outcome_id, label = pref_name, value = pref_name),

        for (i in 1:input$numoc) {
            name_list<-append(name_list, input[[paste("ocrank", i, sep = "")]])
        do.call(tagList, unlist(mylist3, recursive = FALSE))


# Run the application 
shinyApp(ui = ui, server = server)

Hi, the renderUI event will be called each time one of the inputs used inside it is changed.
and you have there: input[[paste("ocrank", i, sep = "")]].
You can put the events that you don't want them to trigger the event inside isolate().
However, the inputs will still back to their default values when you change the values input$inp1 and input$numoc, and if you put them inside isolate() they will no longer trigger the event.
I think you should change the full creation process, and maybe use of insertUI and removeUI will be better in this case: Insert and remove UI objects

1 Like

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.