Learn R Programming

yonder (version 0.1.1)

badgeElement: Badges

Description

Small highlighted content which scales to its parent's size. A badge may be dynamically updated with replaceElement().

Usage

badgeElement(id, ...)

Arguments

id

A character string specifying a reactive id.

...

Named arguments passed as HTML attributes to the parent element or tag elements passed as children to the parent element.

Example application

ui <- container(
  buttonInput(
    id = "clicker",
    label = list(
      "Clicks",
      badgeElement("counter") %>%
        margin(left = 2) %>%
        background("teal")
    )
  )
)

server <- function(input, output) { observe({ clicks <- if (is.null(input$clicker)) 0 else input$clicker replaceElement("counter", clicks) }) }

shinyApp(ui, server)

Details

Use replaceElement() and removeElement() to modify the contents of a badge.

See Also

Other rendering: outputElement

Examples

Run this code
# NOT RUN {
### Possible colors

colors <- c(
  "red", "purple", "indigo", "blue", "cyan", "teal", "green",
  "yellow", "amber", "orange", "grey", "white"
)

div(
  lapply(colors, function(color) {
    badgeElement(color, color) %>%
      background(color) %>%
      margin(2) %>%
      padding(1)
  })
) %>%
  display("flex") %>%
  flex(wrap = TRUE)

# }

Run the code above in your browser using DataLab