% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/toolbar.R
\name{toolbar_input_select}
\alias{toolbar_input_select}
\alias{update_toolbar_input_select}
\title{Toolbar Input Select}
\usage{
toolbar_input_select(
  id,
  label,
  choices,
  ...,
  selected = NULL,
  icon = NULL,
  show_label = FALSE,
  tooltip = !show_label
)

update_toolbar_input_select(
  id,
  label = NULL,
  show_label = NULL,
  choices = NULL,
  selected = NULL,
  icon = NULL,
  session = get_current_session()
)
}
\arguments{
\item{id}{The input ID.}

\item{label}{The input label. By default, \code{label} is not shown but is used by
\code{tooltip}. Set \code{show_label = TRUE} to show the label (see \code{tooltip} for
details on how this affects the tooltip behavior).}

\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 \verb{<optgroup>} HTML tag) for the elements in the respective sublist. See
the example section for a small demo of this feature.}

\item{...}{Additional named arguments passed as attributes to the outer
container div.}

\item{selected}{The initially selected value. If not provided on input creation, the
first choice will be selected by default.
If provided in \code{update_toolbar_input_select()} with a new set of
\code{choices}, it will replace the currently selected value.}

\item{icon}{An icon. If provided without \code{show_label = TRUE}, only the icon
will be visible.}

\item{show_label}{Whether to show the label text. If \code{FALSE} (the default),
only the icon is shown (if provided). If \code{TRUE}, the label text is shown
alongside the icon. Note that \code{show_label} can be dynamically updated using
\code{\link[=update_toolbar_input_button]{update_toolbar_input_button()}}.}

\item{tooltip}{Tooltip text to display when hovering over the input. Can be:
\itemize{
\item \code{TRUE} (default when \code{show_label = FALSE}) - shows a tooltip with the
\code{label} text
\item \code{FALSE} (default when \code{show_label = TRUE}) - no tooltip
\item A character string - shows a tooltip with custom text
}

Defaults to \code{!show_label}. When a tooltip is created, it will have an ID of
\code{"{id}_tooltip"} which can be used to update the tooltip text dynamically
via \code{\link[=update_tooltip]{update_tooltip()}}.}

\item{session}{A Shiny session object (the default should almost always be
used).}
}
\value{
Returns a select input control suitable for use in a toolbar.
}
\description{
Create a select input control that can be used to choose a single item from
a list of values, suitable for use within a \code{\link[=toolbar]{toolbar()}}.
}
\details{
When a tooltip is created for the select input, it will have an ID of
\code{"{id}_tooltip"} which can be used to update the tooltip text dynamically
via \code{\link[=update_tooltip]{update_tooltip()}}.
}
\section{Functions}{
\itemize{
\item \code{toolbar_input_select()}: Create a toolbar select input.

\item \code{update_toolbar_input_select()}: Update a toolbar select input.

}}
\section{Updating toolbar select inputs}{


You can update the appearance and choices of a toolbar select input. This
function works similarly to \code{\link[shiny:updateSelectInput]{shiny::updateSelectInput()}}, but is specifically
designed for \code{\link[=toolbar_input_select]{toolbar_input_select()}}. It allows you to update the select's
label, icon, choices, selected value, and label visibility from the server.

Note that you cannot enable or disable the \code{tooltip} parameter after the
select has been created, only update the text of the tooltip.
When a tooltip is created for the select input, it will have an ID of
\code{"{id}_tooltip"} which can be used to update the tooltip text dynamically
via \code{\link[=update_tooltip]{update_tooltip()}}.

For example:

\if{html}{\out{<div class="sourceCode r">}}\preformatted{library(shiny)
library(bslib)

ui <- page_fluid(
  toolbar(
    align = "right",
    toolbar_input_select(
      "select",
      label = "Choose",
      icon = bsicons::bs_icon("filter"),
      choices = c("A", "B", "C")
    ),
    toolbar_input_button(
      "change_choices",
      label = "Change Choices",
      show_label = TRUE,
      icon = bsicons::bs_icon("arrow-repeat")
    )
  ),
  verbatimTextOutput("value")
)

server <- function(input, output, session) \{
  output$value <- renderPrint(\{
    input$select
  \})

  observeEvent(input$change_choices, \{
    update_toolbar_input_select(
      "select",
      label = "Pick one",
      choices = c("hi", "hello", "hey"),
      selected = "hello"
    )
    # Update the tooltip text
    update_tooltip("select_tooltip", "Choose your NEW option")
  \})
\}

shinyApp(ui, server)
}\if{html}{\out{</div>}}
}

\examples{
\dontshow{if (rlang::is_interactive()) withAutoprint(\{ # examplesIf}
toolbar(
  align = "right",
  toolbar_input_select(
    id = "select",
    label = "Choose option",
    choices = c("Option 1", "Option 2", "Option 3"),
    selected = "Option 2"
  )
)
\dontshow{\}) # examplesIf}
}
\seealso{
Other toolbar components:
\code{\link[=toolbar]{toolbar()}},
\code{\link[=toolbar_divider]{toolbar_divider()}},
\code{\link[=toolbar_input_button]{toolbar_input_button()}}
}
\concept{toolbar components}
