11

Shiny function selectInput() gives an option to select multiple items from the dropdown list with 'multiple = TRUE'

However I want to restrict user on how many items max can be chosen from underlying dropdown list.

Can you please suggest if that is possible with Shiny.

Appreciate for any pointer.

Thanks,

Soma
  • 123
  • 2
  • 6

1 Answers1

15

You can do this if you define it as selectizeInput() instead of selectInput(), and use the options = list(maxItems = n) parameter.

For example

selectizeInput("select", "Select", LETTERS, options = list(maxItems = 4))
DeanAttali
  • 25,268
  • 10
  • 92
  • 118
  • Thanks. This is what I wanted to try. However selectizeInput automatically selects the 1st element (here 'A'). How can I stop this from happening? Means, initially I want the input field would remain blank, then user will select Max 4 elements from the list – Soma May 24 '17 at 15:42
  • Alright, I got the way from https://stackoverflow.com/questions/24175997/no-default-select – Soma May 24 '17 at 15:53
  • i think simply adding `selected = NULL` will do the trick, I think the documentation for selectInput mentions that – DeanAttali May 26 '17 at 01:53