从 selectizeInput 获取不完整的输入

Get incomplete input from selectizeInput

我正在使用 selectizeInput 以获得可自动完成的单词列表,如下面的应用程序所示。

server <- function(input, output) {
    output$word <- renderText({
        input$selInp
    })
}

ui <- fluidPage(
    sidebarLayout(
        sidebarPanel(
            selectizeInput('selInp', label  ='', 
                           selected = 'like',
                           choices = c('like','eat','apples','bananas'))
        ),
        textOutput('word')
    )
)

shinyApp(ui = ui, server = server)

我想做的是接收与 choices 不匹配的输出。所以如果我写 "orange" 我希望能够在 textOutput 中显示它。有没有办法告诉 selectizeInput 不要对它需要的输入如此挑剔?

我相信您正在寻找 create 选项:

library(shiny)

server <- function(input, output) {
  output$word <- renderText({
    input$selInp
  })
}

ui <- fluidPage(
  sidebarLayout(
    sidebarPanel(
      selectizeInput('selInp', label  ='', 
                     selected = 'like',
                     options = list('create' = TRUE),
                     choices = c('like','eat','apples','bananas'))
    ),
    textOutput('word')
  )
)

shinyApp(ui = ui, server = server)