Limiting the number of selections in selecInput

1,131 views
Skip to first unread message

Rishi Agrawal

unread,
Feb 13, 2015, 7:23:53 AM2/13/15
to shiny-...@googlegroups.com
Hi,
How can I limit the number of selections that a user can  make in selectInput. I am giving about 14 selections and I want the user to select atmost 2.

Clifford Long

unread,
Feb 13, 2015, 8:22:37 AM2/13/15
to shiny-...@googlegroups.com
Would an indirect way be to use two selection inputs, each using the same list and each allowing only one input?  The second list would not require an input, and could be reactively pruned to remove whatever is selected in the first choice.

There are probably better ways to do this using shiny, but this came to mind as maybe an interim approach.

Best,

Cliff

Winston Chang

unread,
Feb 13, 2015, 12:45:28 PM2/13/15
to Rishi Agrawal, shiny-discuss
You can do it with a selectizeInput and the options argument. This allows you to pass arguments to the selectize.js library. Here's an example you can run:


shinyApp(
  ui = bootstrapPage(
    selectizeInput("variable", "Variable:", c("One", "Two", "Three"),
      multiple = TRUE,
      options = list(maxItems = 2))
  ),
  server = function(input, output) { }
)


-Winston

On Fri, Feb 13, 2015 at 6:23 AM, Rishi Agrawal <agrawal...@gmail.com> wrote:
Hi,
How can I limit the number of selections that a user can  make in selectInput. I am giving about 14 selections and I want the user to select atmost 2.

--
You received this message because you are subscribed to the Google Groups "Shiny - Web Framework for R" group.
To unsubscribe from this group and stop receiving emails from it, send an email to shiny-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/shiny-discuss/0ae12f8a-6280-4aaf-9394-800fdef4758e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages