| toolbar_input_button | R Documentation |
A button designed to fit well in small places such as in a toolbar().
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()
)
id |
The input ID. |
label |
The input label. By default, |
icon |
An icon. If provided without |
show_label |
Whether to show the label text. If |
tooltip |
Tooltip text to display when hovering over the input. Can be:
Defaults to |
... |
Additional attributes to pass to the button. |
disabled |
If |
border |
Whether to show a border around the button. |
session |
A Shiny session object (the default should almost always be used). |
Returns a button suitable for use in a toolbar.
toolbar_input_button(): Create a toolbar button.
update_toolbar_input_button(): Update a toolbar button.
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)
Other toolbar components:
toolbar(),
toolbar_divider(),
toolbar_input_select()
# Basic toolbar button
toolbar(
toolbar_input_button(id = "view", icon = icon("eye"), label = "View"),
toolbar_input_button(id = "save", icon = icon("save"), label = "Save")
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.