View source: R/brand_use_logo.R
| brand_use_logo | R Documentation |
Returns a brand logo resource specified by name and variant from a brand
object. The image paths in the returned object are adjusted to be absolute,
relative to the location of the brand YAML file, if brand was read from a
file, or the local working directory otherwise.
brand_use_logo(
brand,
name,
variant = c("auto", "light", "dark", "light-dark"),
...,
.required = !name %in% c("small", "medium", "large", "smallest", "largest"),
.allow_fallback = TRUE
)
brand |
A brand object from |
name |
The name of the logo to use. Either a size ( |
variant |
Which variant to use, only used when
|
... |
Additional named attributes to be added to the image HTML or
markdown when created via |
.required |
Logical or character string. If |
.allow_fallback |
If |
A brand_logo_resource object, a brand_logo_resource_light_dark
object, or NULL if the requested logo doesn't exist and .required is
FALSE.
You can use brand_use_logo() to include logos in Shiny apps or in HTML documents produced by
Quarto or R Markdown.
In Shiny apps, logos returned by brand_use_logo() will automatically be
converted into HTML tags using htmltools::as.tags(), so you can include
them directly in your UI code.
library(shiny)
library(bslib)
brand <- read_brand_yml()
ui <- page_navbar(
title = tagList(
brand_use_logo(brand, "small"),
"Brand Use Logo Test"
),
nav_panel(
"Page 1",
card(
card_header("My Brand"),
brand_use_logo(brand, "medium", variant = "dark")
)
)
# ... The rest of your app
)
If your brand includes a light/dark variant for a specific size, both images
will be included in the app, but only the appropriate image will be shown
based on the user's system preference of the app's current theme mode if you
are using bslib::input_dark_mode().
To include additional classes or attributes in the <img> tag, you can call
htmltools::as.tags() directly and provide those attributes:
brand <- as_brand_yml(list(
logo = list(
images = list(
"cat-light" = list(
path = "https://placecats.com/louie/300/300",
alt = "A light-colored tabby cat on a purple rug"
),
"cat-dark" = list(
path = "https://placecats.com/millie/300/300",
alt = "A dark-colored cat looking into the camera"
),
"cat-med" = "https://placecats.com/600/600"
),
small = list(light = "cat-light", dark = "cat-dark"),
medium = "cat-med"
)
))
brand_use_logo(brand, "small") |>
htmltools::as.tags(class = "my-logo", height = 32)
The same applies to HTML documents produced by Quarto or R Markdown, where images can be used in-line:
```{r}
brand_use_logo(brand, "small")
```
This is my brand's medium sized logo: `r brand_use_logo(brand, "medium")`
Finally, you can use format() to convert the logo to raw HTML or markdown:
cat(format(brand_use_logo(brand, "small", variant = "light")))
#> <img src="https://placecats.com/louie/300/300" alt="A light-colored tabby cat on a purple rug" class="brand-logo"/>
cat(format(
brand_use_logo(brand, "medium"),
.format = "markdown",
class = "my-logo",
height = 500
))
#> {.brand-logo .my-logo alt="" height="500"}
brand <- as_brand_yml(list(
logo = list(
images = list(
small = "logos/small.png",
huge = list(path = "logos/huge.png", alt = "Huge Logo")
),
small = "small",
medium = list(
light = list(
path = "logos/medium-light.png",
alt = "Medium Light Logo"
),
dark = list(path = "logos/medium-dark.png")
)
)
))
brand_use_logo(brand, "small")
brand_use_logo(brand, "medium")
brand_use_logo(brand, "large")
brand_use_logo(brand, "huge")
brand_use_logo(brand, "small", variant = "light")
brand_use_logo(brand, "small", variant = "light", allow_fallback = FALSE)
brand_use_logo(brand, "small", variant = "light-dark")
brand_use_logo(
brand,
"small",
variant = "light-dark",
allow_fallback = FALSE
)
brand_use_logo(brand, "medium", variant = "light")
brand_use_logo(brand, "medium", variant = "dark")
brand_use_logo(brand, "medium", variant = "light-dark")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.