Skip to contents

Builds a deck of bootstrap cards

cards(
  data,
  title = NULL,
  text = NULL,
  image = NULL,
  link = NULL,
  footer = NULL,
  header = NULL,
  tags = NULL,
  layout = "label-below",
  width = 3,
  spacing = 2,
  breakpoint = 4,
  label_colour = NULL,
  border_colour = NULL,
  border_width = 1,
  border_radius = 3
)

Arguments

data

Data frame

title

Title for the card

text

Text for the card

image

Path to the card image

link

URL to link to from title and image

footer

Card footer

header

Card header

tags

Tags to be assigned to each card

layout

Card layout is a string, defaults to "label-below" (see details)

width

Card width is an integer between 1 and 5

spacing

Spacing between cards is an integer between 0 and 5

breakpoint

Number between 1 and 5, controlling label size on horizontal and inset layouts

label_colour

Colour applied to the card label (if NULL, colour inherits)

border_colour

Colour applied to the card border (if NULL, colour inherits)

border_width

Width of card border is an integer between 0 and 5

border_radius

Amount of rounding on card corners is an integer between 0 and 5

Value

A "shiny.tag" object containing the HTML for the card deck

Details

This function constructs the HTML necessary to specify a deck of bootstrap 4 cards suitable for inclusion within an R markdown document. It takes a data frame as the first argument, with one row for each card to be generated.

Cards are specified using the title, text, image, link, footer, header, and tags arguments. These arguments take expressions to be evaluated using the user-supplied data, and should evaluate to character vectors that have length 1 or the same number of rows as data.

The layout argument is a single character string specifying the layout of the cards: possible values are "label-below" (the default), "label-above", "label-left", "label-right", "label-only", "image-only", "inset-top", "inset-bottom".

The width, spacing, breakpoint, border_width, and border_radius arguments all take integer inputs specifying the visual appearance of the cards. Allowed values range from 0 to 5, except for width and breakpoint which cannot be 0. The other two arguments label_colour and border_colour take a single string specifying colours of the relevant parts of the card.

Examples

if (FALSE) {
galleries %>%
  cards(
    title = long_name,
    text = blurb,
    image = image_url,
    link = gallery_url
  )
}