Description Usage Arguments Examples
Create a tagList of action buttons using the actionButtonUI wrapper for shiny::actionButton.
1 2 |
ids |
A unique string id for the numericInput. If your code is modularised, remember to wrap the id with the relevant session namespace function, e.g. numericValueUI(id = session$ns("someinput")). |
labels |
A label for the input. |
icons |
Icons for the action buttons. |
widths |
The widths of the action buttons. Must be valid css (i.e. "10%" or "150px" will work; see shiny::validateCssUnit). To use the same width on all action buttons, provide a single-text string or a vector with one text string. To use different widths for each action button, provide a vector of custom css text strings with one element per action button. |
custom_css |
If provided, the action buttons are wrapped in divs each styled by the custom_css input. For example, when creating multiple action buttons, one could provide custom_css = "display: inline-block;" to display the action buttons inline. To use the same style on all action buttons, provide a single-text string or single-element vector. To use different styles for each action button, provide a vector of custom css text strings with one element per action button. |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | if (interactive()) {
####################################################################
# Suppose we want three action buttons that increments separate counters.
# We first need to define UI and server-side logic for the buttons.
####################################################################
pacman::p_load_current_gh(c("kahaaga/shinymodules", "rstudio/shiny"))
# Function that displays the UI created server-side.
actionButtonTestUI <- function(id) {
ns <- NS(id)
fluidRow(uiOutput(ns("increment_buttons")))
}
# Server-side module that generates the action buttons.
actionButtonTest <- function(input, output, session) {
output$increment_buttons <- renderUI({
button_ids = c("increment1", "increment2", "woopdidoop")
shinymodules::actionButtonUIs(
ids = sapply(button_ids, session$ns),
labels = paste0("I'm a button with id '", button_ids,
"'. Push me, please."),
widths = paste0(c(200, 300, 400), "px"),
custom_css = "display: inline-block"
)
})
}
ui <- fluidPage(
# Let's suppose we have a page where we want the action button
# to appear. Here we call the UI logic. We'll also add a textOutput
# showing the number of times the button has been clicked.
fluidRow(
actionButtonTestUI(id = "helppage"),
textOutput("numclicks1"),
textOutput("numclicks2"),
textOutput("numclickswoop")
)
server <- function(input, output, session) {
# Call the module that generates the action button.
callModule(module = actionButtonTest, id = "helppage")
# The number of times the button has been clicked
output$numclicks1 <- renderText({input[["helppage-increment1-actionbutton"]]})
output$numclicks2 <- renderText({input[["helppage-increment2-actionbutton"]]})
output$numclickswoop <- renderText({input[["helppage-woopdidoop-actionbutton"]]})
}
shinyApp(ui = ui, server = server)
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.