knitr::opts_chunk$set( collapse = TRUE, comment = "#>" ) library(tibble)
library(bs4cards)
The bs4cards package supports a total eight different layout formats. First, there are two vertical layouts and two horizontal layouts:
layout = "label-below" places the label below the image (the default)layout = "label-above" places the label above the imagelayout = "label-left" places the label to the left of the imagelayout = "label-right" places the label to the right of the imageIn addition there are two "singleton" layouts:
layout = "label-only" includes a label but no imagelayout = "image-only" includes an image but no labelFinally there are two "inset" layouts"
layout = "inset-top" places the label at the top of the imagelayout = "inset-bottom" places the label at the bottom of the imageThe vertical label-below layout is the default for bs4cards. Images are placed above the label, with the label title above text. Footers (if present) appear under the label, and the header (if present) is shown above:
galleries %>% cards( title = long_name, link = gallery_url, image = image_url, layout = "label-below" )
The label-above layout reverses the positions of label and image:
galleries %>% cards( title = long_name, link = gallery_url, image = image_url, layout = "label-above" )
Horizontal card layouts are also supported in bs4cards, by setting layout = "label-left" or layout = "label-right". Here's an example:
galleries %>% cards( title = long_name, link = gallery_url, image = image_url, text = blurb, footer = date, layout = "label-right", width = 4 )
Horizontal layouts tend to need more horizontal space, especially when the label includes text as well as a title. In the code above I set width = 4 to provide a little more room. You can also adjust the location of the breakpoint separating the image and the label. The breakpoint argument should be an integer between 1 and 5.
galleries[1,] %>% cards( title = long_name, image = image_url, text = blurb, layout = "label-left", breakpoint = 1, width = 4 )
galleries[1,] %>% cards( title = long_name, image = image_url, text = blurb, layout = "label-left", breakpoint = 5, width = 4 )
In some cases there is no label to accompany the image, in which case setting layout = "image-only" is appropriate:
galleries[1:3, ] %>% cards( link = gallery_url, image = image_url, layout = "image-only" )
It is still possible to add headers and footers, however:
galleries[1:3, ] %>% cards( link = gallery_url, image = image_url, footer = long_name, layout = "image-only" )
The inversion of the image-only layout is the label-only layout, which is appropriate whenever no image is included. This is not the most visually exciting layout, but there are situations where it may be handy:
galleries %>% cards( link = gallery_url, title = long_name, text = blurb, layout = "label-only" )
The remaining two layout types are "inset" types, in which the label is displayed as an overlay on top of the image.
galleries %>% cards( title = long_name, text = blurb, link = gallery_url, image = image_url, layout = "inset-top" )
Like horizontal cards, inset cards use the breakpoint argument to specify the amount of space occupied by the label. The inset occupies a fixed proportion of the image height, so a little care is required. The smallest size (breakpoint = 1) is generally tall enough to accommodate a single line title:
galleries[1,] %>% cards(title = long_name, image = image_url, layout = "inset-top", breakpoint = 1)
The largest size is breakpoint = 5 and is large enough to fit a modest caption:
galleries[1,] %>% cards(title = long_name, image = image_url, text = blurb, layout = "inset-top", breakpoint = 5)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.