0
votes

I'm attempting to use InsertUI and updateSelectizeInput methods in the server function as part of my app, primarily since my list of choices is so large.

library(shiny)

baby_names <- babynames::babynames %>% 
  distinct(name) %>%
  .[["name"]] %>% 
  sort()

ui <- fluidPage(
  tags$div(id = 'placeholder')
)

server <- function(input, output, session) {
  id = "babies"
  insertUI(selector = '#placeholder',
           ui = tags$div(list(
             selectizeInput("babynames", label = "Baby Names!", multiple = TRUE, choices = NULL, width = '400px',
                            options = list(placeholder = 'Type a baby name.'))
           ), 
           immediate = TRUE, 
           id = id))

    updateSelectizeInput(
      session, inputId = "babynames",
      choices = baby_names,
      server = TRUE)

}

shinyApp(ui, server)

I'm not getting much success out of this, as the selectizeInput is displayed but the dropdown options are not shown. How should I address this issue? Thanks!

1

1 Answers

-1
votes

This is explained in the documentation of insertUI:

This function allows you to dynamically add an arbitrarily large UI object into your app, whenever you want, as many times as you want. Unlike renderUI(), the UI generated with insertUI is not updatable as a whole: once it's created, it stays there. Each new call to insertUI creates more UI objects, in addition to the ones already there (all independent from one another). To update a part of the UI (ex: an input object), you must use the appropriate render function or a customized reactive function

(I added the bold font)

Therefore, you should use renderUI instead.