% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/toolbar.R
\name{toolbar_input_button}
\alias{toolbar_input_button}
\alias{update_toolbar_input_button}
\title{Add a toolbar input button}
\usage{
toolbar_input_button(
  id,
  label,
  icon = NULL,
  show_label = is.null(icon),
  tooltip = !show_label,
  ...,
  disabled = FALSE,
  border = FALSE
)

update_toolbar_input_button(
  id,
  label = NULL,
  show_label = NULL,
  icon = NULL,
  disabled = 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{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{...}{Additional attributes to pass to the button.}

\item{disabled}{If \code{TRUE}, the button will not be clickable. Use
\code{\link[=update_toolbar_input_button]{update_toolbar_input_button()}} to dynamically enable/disable the button.}

\item{border}{Whether to show a border around the button.}

\item{session}{A Shiny session object (the default should almost always be
used).}
}
\value{
Returns a button suitable for use in a toolbar.
}
\description{
A button designed to fit well in small places such as in a \code{\link[=toolbar]{toolbar()}}.
}
\section{Functions}{
\itemize{
\item \code{toolbar_input_button()}: Create a toolbar button.

\item \code{update_toolbar_input_button()}: Update a toolbar button.

}}
\section{Updating toolbar buttons}{


You can dynamically update the appearance and enabled/disabled state
of a toolbar button on the client side using \code{\link[=update_toolbar_input_button]{update_toolbar_input_button()}}.
This function works similarly to \code{\link[shiny:updateActionButton]{shiny::updateActionButton()}}.

Note that you cannot change the \code{tooltip} or \code{border} parameters after the
button has been created, as these affect the button's structure and ARIA
attributes.
Please use \code{\link[=update_tooltip]{update_tooltip()}} to update the text of the tooltip if one is
present.

For example:

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

ui <- page_fluid(
  card(
    card_header(
      "Toolbar Demo",
      toolbar(
        align = "right",
        toolbar_input_button("btn", label = "Click me", icon = icon("play")),
        toolbar_input_button(
          "task",
          label = "Do a Task",
          icon = icon("play-circle"),
          show_label = TRUE
        )
      )
    ),
    card_body(
      verbatimTextOutput("count")
    )
  )
)

server <- function(input, output, session) \{
  output$count <- renderPrint(\{
    input$btn
  \})

  observeEvent(input$btn, \{
    update_toolbar_input_button(
      "btn",
      label = "Clicked!",
      icon = icon("check")
    )
    # Update the tooltip text
    update_tooltip("btn_tooltip", "Button was clicked!")
  \})

  # Handle task button - toggle between states
  observeEvent(input$task, \{
    if (input$task \%\% 2 == 1) \{
      # Show task is in progress
      update_toolbar_input_button(
        "task",
        label = "Task Running...",
        icon = icon("spinner")
      )
    \} else \{
      # Reset to original
      update_toolbar_input_button(
        "task",
        label = "Do a Task",
        icon = icon("play-circle"),
        session = session
      )
    \}
  \})
\}

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

\examples{
\dontshow{if (rlang::is_interactive()) withAutoprint(\{ # examplesIf}
# Basic toolbar button
toolbar(
  toolbar_input_button(id = "view", icon = icon("eye"), label = "View"),
  toolbar_input_button(id = "save", icon = icon("save"), label = "Save")
)
\dontshow{\}) # examplesIf}
}
\seealso{
Other toolbar components:
\code{\link[=toolbar]{toolbar()}},
\code{\link[=toolbar_divider]{toolbar_divider()}},
\code{\link[=toolbar_input_select]{toolbar_input_select()}}
}
\concept{toolbar components}
