0
votes

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

3
Probably selectize is what you need: shiny.rstudio.com/articles/selectize.htmlIcaro Bombonato
The answers to this question might help youChriiSchee
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 and referencedracodoc

3 Answers

4
votes

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

2
votes

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

0
votes

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.