1

Is there any way that we can provide available options while using textInput in shiny similar to shiny selectinput option?

That is, if a user types a letter or character, all available options within the letter or character must be provided. Since I have a lot of options, selectinput kind of slows down and not a good option for the input. Therefore, I opt for textInput.

Any suggestions will be helpful!

Thanks

Prradep
  • 5,506
  • 5
  • 43
  • 84
  • 1
    Probably selectize is what you need: http://shiny.rstudio.com/articles/selectize.html – Icaro Bombonato May 25 '16 at 12:47
  • The answers to this [question](http://stackoverflow.com/questions/35265920/auto-complete-and-selection-of-multiple-values-in-text-box-shiny) might help you – ChriiSchee Aug 31 '16 at 08:52
  • To clarify some confusion: By default, selectInput() and selectizeInput() use the JavaScript library selectize.js. Unless you choose the basic input specifically on selectInput() with `selectize=FALSE`. So everybody is talking about different modes of `selectize` already. See [gallery](http://shiny.rstudio.com/gallery/selectize-vs-select.html) and [reference](https://shiny.rstudio.com/reference/shiny/latest/selectInput.html) – dracodoc Mar 30 '17 at 14:47

3 Answers3

4

You can use selectInput with argument multiple = TRUE

selectInput(inputId, label, choices, multiple = TRUE)

This will output a text box rather than drop down and as user starts typing all the available options within the letter will be filtered.

Create a select list input control

Example

abhy3
  • 262
  • 6
  • 18
2

using DT, you can do some fancy stuff. Following is an example where the table lists all the options that contain the text you typed. If you click on a table cell, the text input is updated with the table cell's text. You can also use the search field of the table.

library(shiny)

shinyApp(
  ui = fluidPage(textInput("text", "Please input text:"),
                 DT::dataTableOutput('tbl')),

  server = function(session, input, output) {

    # all your choices for the textfield go into "text" column
    allData <- data.frame(ID = '', text = c(paste0("Text",1:50)))

    # table with only the texts that contain input$text
    output$tbl = DT::renderDataTable(
      allData[grep(input$text, allData$text), ],
      selection = 'none',
      rownames = FALSE,
      options = list(searchHighlight=T)
    )

    # fill textInput after Click in Table
    observeEvent(input$tbl_cell_clicked, {
      info <- input$tbl_cell_clicked

      if (is.null(info$value) || info$col != 1) return()
      else {
       updateTextInput(session, "text", value = info$value)
      }
    })
  }
)

enter image description here

shosaco
  • 5,915
  • 1
  • 30
  • 48
0

selectinput kind of slows down and not a good option for the input

selectInput with multiple choice is the best option in this case. The slow loading can be easily managed by moving selectInput into server.

Just type in ui.R:

selectizeInput(inputId=..., label=..., choices = NULL, multiple = TRUE)

and in server.R:

server <-  function(input, output, session) {
    updateSelectizeInput(session = session,inputId =...,choices=..., server = TRUE)}

Now You should not have any problems with slow loading.

Mal_a
  • 3,670
  • 1
  • 27
  • 60