| toolbar_input_select | R Documentation |
Create a select input control that can be used to choose a single item from
a list of values, suitable for use within a toolbar().
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()
)
id |
The input ID. |
label |
The input label. By default, |
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 |
... |
Additional named arguments passed as attributes to the outer container div. |
selected |
The initially selected value. If not provided on input creation, the
first choice will be selected by default.
If provided in |
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 |
session |
A Shiny session object (the default should almost always be used). |
When a tooltip is created for the select input, it will have an ID of
"{id}_tooltip" which can be used to update the tooltip text dynamically
via update_tooltip().
Returns a select input control suitable for use in a toolbar.
toolbar_input_select(): Create a toolbar select input.
update_toolbar_input_select(): Update a toolbar select input.
You can update the appearance and choices of a toolbar select input. This
function works similarly to shiny::updateSelectInput(), but is specifically
designed for 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 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
"{id}_tooltip" which can be used to update the tooltip text dynamically
via update_tooltip().
For example:
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)
Other toolbar components:
toolbar(),
toolbar_divider(),
toolbar_input_button()
toolbar(
align = "right",
toolbar_input_select(
id = "select",
label = "Choose option",
choices = c("Option 1", "Option 2", "Option 3"),
selected = "Option 2"
)
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.