4
votes

I have a selectInput with all the possible choices displayed. I want to implement it such that if a user types something in the box and hits enter, that will also be added as a choice.

observeEvent(input$mykeypress, {

if(input$mykeypress == 13){

    print(input$selectBox)

}

I tried the above code to see if my input changed, but it seems that no matter what extra stuff I type in the selectbox, none of it is recognized.

Anyone have ideas as to have I can recognize anything extra that the user types?

Edit: One other idea I am considering is creating a textInput, and prepopulating it with all the values that I used in my selectbox. Is something like that possible?

1
See autocomplete feature of jQuery - MaxZoom
@MaxZoom I don't want the user to be selecting from a pre-populated list. I want to allow them to type any input they please and have it show up upon pressing enter - Green
You should build the selectInput in the server using renderUI. Then you can make the choices reactive. - Carl
Sounds more like you want textInput rather than a selectInput. shiny.rstudio.com/reference/shiny/latest/textInput.html - Brandon Bertelsen
I think you guys aren't fully understanding exactly what I want. To clarify, in a selectInput with multiple = TRUE, you can allow all the selections to show up by using the selected feature. I then want the user to be able to add selections by simply typing then pressing enter. The user should also be able to click on selections and delete them by pressing the backspace key (normal functionality of a selectInput) - Green

1 Answers

7
votes

I ended up figuring it out, because the selectizeInput just wraps around selectize.js, in your selectizeInput you can use the argument: options = list(create = TRUE), and the user can add words easily.