diff --git a/NAMESPACE b/NAMESPACE index 4baa3f2..86b080b 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -17,6 +17,7 @@ export(page_386) export(progress_386) export(radio_input_386) export(remove_modal_386) +export(select_input_386) export(show_modal_386) export(show_toast_386) export(text_area_input_386) @@ -26,6 +27,7 @@ export(toggle_input_386) export(update_checkbox_input_386) export(update_progress_386) export(update_radio_input_386) +export(update_select_input_386) export(update_toggle_input_386) export(use_bs4_deps) export(validate_progress_value) diff --git a/R/inputs.R b/R/inputs.R index 0ff3f2a..d808720 100644 --- a/R/inputs.R +++ b/R/inputs.R @@ -332,3 +332,70 @@ update_radio_input_386 <- function(session, inputId, label = NULL, choices = NUL choiceValues ) } + + + +#' Create a Bootstrap 386 select input +#' @inheritParams shiny::selectInput +#' @export +#' @examples +#' if (interactive()) { +#' library(shiny) +#' library(shiny386) +#' +#' ui <- page_386( +#' select_input_386("variable", "Variable:", +#' c("Cylinders" = "cyl", +#' "Transmission" = "am", +#' "Gears" = "gear")), +#' tableOutput("data") +#' ) +#' +#' server <- function(input, output, session) { +#' output$data <- renderTable({ +#' mtcars[, c("mpg", input$variable), drop = FALSE] +#' }, rownames = TRUE) +#' } +#' shinyApp(ui, server) +#' +#' } +select_input_386 <- shiny::selectInput + + + +#' Update a Bootstrap 386 select input on the client +#' @inheritParams shiny::updateSelectInput +#' @export +#' @examples +#' if (interactive()) { +#' library(shiny) +#' library(shiny386) +#' +#' ui <- page_386( +#' p("The radio group controls the select input"), +#' radio_input_386("inCheckboxGroup", "Input checkbox", +#' c("Item A", "Item B", "Item C")), +#' select_input_386("inSelect", "Select input", +#' c("Item A", "Item B", "Item C")) +#' ) +#' +#' server <- function(input, output, session) { +#' observe({ +#' x <- input$inCheckboxGroup +#' +#' # Can use character(0) to remove all choices +#' if (is.null(x)) +#' x <- character(0) +#' +#' # Can also set the label and select items +#' update_select_input_386(session, "inSelect", +#' label = paste("Select input label", length(x)), +#' choices = x, +#' selected = tail(x, 1) +#' ) +#' }) +#' } +#' +#' shinyApp(ui, server) +#' } +update_select_input_386 <- shiny::updateSelectInput diff --git a/man/select_input_386.Rd b/man/select_input_386.Rd new file mode 100644 index 0000000..777e1be --- /dev/null +++ b/man/select_input_386.Rd @@ -0,0 +1,70 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/inputs.R +\name{select_input_386} +\alias{select_input_386} +\title{Create a Bootstrap 386 select input} +\usage{ +select_input_386( + inputId, + label, + choices, + selected = NULL, + multiple = FALSE, + selectize = TRUE, + width = NULL, + size = NULL +) +} +\arguments{ +\item{inputId}{The \code{input} slot that will be used to access the value.} + +\item{label}{Display label for the control, or \code{NULL} for no label.} + +\item{choices}{List of values to select from. If elements of the list are +named, then that name --- rather than the value --- is displayed to the +user. It's also possible to group related inputs by providing a named list +whose elements are (either named or unnamed) lists, vectors, or factors. In +this case, the outermost names will be used as the group labels (leveraging +the \code{} HTML tag) for the elements in the respective sublist. See +the example section for a small demo of this feature.} + +\item{selected}{The initially selected value (or multiple values if \code{multiple = TRUE}). If not specified then defaults to the first value for +single-select lists and no values for multiple select lists.} + +\item{multiple}{Is selection of multiple items allowed?} + +\item{selectize}{Whether to use \pkg{selectize.js} or not.} + +\item{width}{The width of the input, e.g. \code{'400px'}, or \code{'100\%'}; +see \code{\link[shiny:validateCssUnit]{validateCssUnit()}}.} + +\item{size}{Number of items to show in the selection box; a larger number +will result in a taller box. Not compatible with \code{selectize=TRUE}. +Normally, when \code{multiple=FALSE}, a select input will be a drop-down list, +but when \code{size} is set, it will be a box instead.} +} +\description{ +Create a Bootstrap 386 select input +} +\examples{ +if (interactive()) { + library(shiny) + library(shiny386) + + ui <- page_386( + select_input_386("variable", "Variable:", + c("Cylinders" = "cyl", + "Transmission" = "am", + "Gears" = "gear")), + tableOutput("data") + ) + + server <- function(input, output, session) { + output$data <- renderTable({ + mtcars[, c("mpg", input$variable), drop = FALSE] + }, rownames = TRUE) + } + shinyApp(ui, server) + +} +} diff --git a/man/update_select_input_386.Rd b/man/update_select_input_386.Rd new file mode 100644 index 0000000..1ca866c --- /dev/null +++ b/man/update_select_input_386.Rd @@ -0,0 +1,69 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/inputs.R +\name{update_select_input_386} +\alias{update_select_input_386} +\title{Update a Bootstrap 386 select input on the client} +\usage{ +update_select_input_386( + session, + inputId, + label = NULL, + choices = NULL, + selected = NULL +) +} +\arguments{ +\item{session}{The \code{session} object passed to function given to +\code{shinyServer}.} + +\item{inputId}{The id of the input object.} + +\item{label}{The label to set for the input object.} + +\item{choices}{List of values to select from. If elements of the list are +named, then that name --- rather than the value --- is displayed to the +user. It's also possible to group related inputs by providing a named list +whose elements are (either named or unnamed) lists, vectors, or factors. In +this case, the outermost names will be used as the group labels (leveraging +the \code{} HTML tag) for the elements in the respective sublist. See +the example section for a small demo of this feature.} + +\item{selected}{The initially selected value (or multiple values if \code{multiple = TRUE}). If not specified then defaults to the first value for +single-select lists and no values for multiple select lists.} +} +\description{ +Update a Bootstrap 386 select input on the client +} +\examples{ +if (interactive()) { + library(shiny) + library(shiny386) + + ui <- page_386( + p("The radio group controls the select input"), + radio_input_386("inCheckboxGroup", "Input checkbox", + c("Item A", "Item B", "Item C")), + select_input_386("inSelect", "Select input", + c("Item A", "Item B", "Item C")) + ) + + server <- function(input, output, session) { + observe({ + x <- input$inCheckboxGroup + + # Can use character(0) to remove all choices + if (is.null(x)) + x <- character(0) + + # Can also set the label and select items + update_select_input_386(session, "inSelect", + label = paste("Select input label", length(x)), + choices = x, + selected = tail(x, 1) + ) + }) + } + + shinyApp(ui, server) +} +}