@@ -745,22 +745,27 @@ choicesWithNames <- function(choices) {
745
745
746
746
# ' Create a select list input control
747
747
# '
748
- # ' Create a select list that can be used to choose a single or
749
- # ' multiple items from a list of values.
748
+ # ' Create a select list that can be used to choose a single or multiple items
749
+ # ' from a list of values.
750
750
# '
751
751
# ' By default, \code{selectInput()} and \code{selectizeInput()} use the
752
- # ' JavaScript library \pkg{selectize.js} (\url{https://github.com/brianreavis/selectize.js})
753
- # ' to instead of the basic select input element. To use the standard HTML select
754
- # ' input element, use \code{selectInput()} with \code{selectize=FALSE}.
752
+ # ' JavaScript library \pkg{selectize.js}
753
+ # ' (\url{https://github.com/brianreavis/selectize.js}) to instead of the basic
754
+ # ' select input element. To use the standard HTML select input element, use
755
+ # ' \code{selectInput()} with \code{selectize=FALSE}.
755
756
# '
756
757
# ' @inheritParams textInput
757
758
# ' @param choices List of values to select from. If elements of the list are
758
- # ' named then that name rather than the value is displayed to the user.
759
+ # ' named then that name rather than the value is displayed to the user.
759
760
# ' @param selected The initially selected value (or multiple values if
760
- # ' \code{multiple = TRUE}). If not specified then defaults to the first value
761
- # ' for single-select lists and no values for multiple select lists.
761
+ # ' \code{multiple = TRUE}). If not specified then defaults to the first value
762
+ # ' for single-select lists and no values for multiple select lists.
762
763
# ' @param multiple Is selection of multiple items allowed?
763
764
# ' @param selectize Whether to use \pkg{selectize.js} or not.
765
+ # ' @param size Number of items to show in the selection box; a larger number
766
+ # ' will result in a taller box. Not compatible with \code{selectize=TRUE}.
767
+ # ' Normally, when \code{multiple=FALSE}, a select input will be a drop-down
768
+ # ' list, but when \code{size} is set, it will be a box instead.
764
769
# ' @return A select list control that can be added to a UI definition.
765
770
# '
766
771
# ' @family input elements
@@ -773,7 +778,8 @@ choicesWithNames <- function(choices) {
773
778
# ' "Gears" = "gear"))
774
779
# ' @export
775
780
selectInput <- function (inputId , label , choices , selected = NULL ,
776
- multiple = FALSE , selectize = TRUE , width = NULL ) {
781
+ multiple = FALSE , selectize = TRUE , width = NULL ,
782
+ size = NULL ) {
777
783
# resolve names
778
784
choices <- choicesWithNames(choices )
779
785
@@ -782,10 +788,15 @@ selectInput <- function(inputId, label, choices, selected = NULL,
782
788
if (! multiple ) selected <- firstChoice(choices )
783
789
} else selected <- validateSelected(selected , choices , inputId )
784
790
791
+ if (! is.null(size ) && selectize ) {
792
+ stop(" 'size' argument is incompatible with 'selectize=TRUE'." )
793
+ }
794
+
785
795
# create select tag and add options
786
796
selectTag <- tags $ select(
787
797
id = inputId ,
788
798
class = if (! selectize ) " form-control" ,
799
+ size = size ,
789
800
selectOptions(choices , selected )
790
801
)
791
802
if (multiple )
0 commit comments