闪亮:selectizeInput 和 textInput 的组合可能吗?

nee*_*elp 5 r shiny

我想在闪亮的应用程序中有一个 textInput,当用户键入某物时,它会向用户显示来自预定义列表(或向量)的可能自动完成。因此,用户可以单击它并节省时间,但也可以编写不在预定义列表中的文本(与 Google 搜索的工作方式类似)。

这是一个例子。用户可以输入“Ap”,然后点击“Apple”。但是也应该可以输入不在预定义列表中的新输入,例如“Orange”。

Shinysky 与我想要的类似(textInput 中的自动完成,但似乎不允许不在选择向量中的新文本。

library(shiny)
library(shinysky) # install from github
choices = c("Apple", "Banana", "Strawberry")

ui <- fluidPage(
  textInput.typeahead(
    id = "fruit", placeholder="type a fruit name", 
    local = data.frame(fruit = choices, info = c("info1", "info2", "info3")), 
    valueKey = "fruit", 
    tokens = c(1, 2, 3), 
    template = HTML("<p class='repo-language'>{{info}}</p> <p class='repo-name'>{{fruit}}</p> <p class='repo-description'>You need to learn more CSS to customize this further</p>")
    ),
  verbatimTextOutput("value")
)

 server <- function(input, output, session) {
   # typeahead
  observe({
    input$fruit
    showshinyalert(session, "shinyalert3", sprintf("Typeahead Text Input Value: '%s'", 
                                               input$fruit), "error")
  })
  output$value <- renderText({input$fruit})
}

shinyApp(ui, server)
Run Code Online (Sandbox Code Playgroud)

也许有人有想法?

nee*_*elp 5

我花了将近两年的时间才找到解决方案:

selectizeInput(..., options = list(create = TRUE))
Run Code Online (Sandbox Code Playgroud)

这里还提到:闪亮 - 寻找组合选择和文本输入的快捷方式