A button designed to fit well in small places such as in a toolbar().
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
- id
The input ID.
- label
The input label. By default,
labelis not shown but is used bytooltip. Setshow_label = TRUEto show the label (seetooltipfor details on how this affects the tooltip behavior).- icon
An icon. If provided without
show_label = TRUE, only the icon will be visible.- show_label
Whether to show the label text. If
FALSE(the default), only the icon is shown (if provided). IfTRUE, the label text is shown alongside the icon. Note thatshow_labelcan be dynamically updated usingupdate_toolbar_input_button().- tooltip
Tooltip text to display when hovering over the input. Can be:
TRUE(default whenshow_label = FALSE) - shows a tooltip with thelabeltextFALSE(default whenshow_label = TRUE) - no tooltipA character string - shows a tooltip with custom text
Defaults to
!show_label. When a tooltip is created, it will have an ID of"{id}_tooltip"which can be used to update the tooltip text dynamically viaupdate_tooltip().- ...
Additional attributes to pass to the button.
- disabled
If
TRUE, the button will not be clickable. Useupdate_toolbar_input_button()to dynamically enable/disable the button.- border
Whether to show a border around the button.
- session
A Shiny session object (the default should almost always be used).
Functions
toolbar_input_button(): Create a toolbar button.update_toolbar_input_button(): Update a toolbar button.
Updating toolbar buttons
You can dynamically update the appearance and enabled/disabled state
of a toolbar button on the client side using update_toolbar_input_button().
This function works similarly to shiny::updateActionButton().
Note that you cannot change the tooltip or border parameters after the
button has been created, as these affect the button's structure and ARIA
attributes.
Please use update_tooltip() to update the text of the tooltip if one is
present.
For example:
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)See also
Other toolbar components:
toolbar(),
toolbar_divider(),
toolbar_input_select()
