使用InsertUI和UpdateSelectizeInput

问题描述 投票:0回答:1

[我试图将服务器功能中的InsertUI和updateSelectizeInput方法用作我的应用程序的一部分,主要是因为我的选择列表很大。

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)

我并没有取得太大的成功,因为显示了selectizeInput,但未显示下拉选项。我应该如何解决这个问题?谢谢!

r shiny
1个回答
0
投票

insertUI的文档中对此进行了解释:

© www.soinside.com 2019 - 2024. All rights reserved.