首页 文章

从selectizeInput获取不完整的输入

提问于
浏览
0

我正在使用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 对所需的输入不是那么有选择性?

1 回答

  • 1

    我相信你正在寻找 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)
    

相关问题