-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from shinyworks/standalone
Add standalone version.
- Loading branch information
Showing
4 changed files
with
71 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Version: 0.1.0 | ||
Date: 2024-10-26 20:06:24 UTC | ||
SHA: 2bee70bc83117035f27771c14607ebc7a9747f4f |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# --- | ||
# repo: shinyworks/favawesome | ||
# file: standalone-fav.R | ||
# last-updated: 2024-10-28 | ||
# license: https://unlicense.org | ||
# imports: [fontawesome, htmltools, jsonlite, rsvg] | ||
# --- | ||
# | ||
# Provides the fav() function from {favawesome} as stand-alone code for use in | ||
# packages that can't import favawesome. See usethis::use_standalone() for usage | ||
# details. | ||
# | ||
# ## Changelog | ||
# | ||
# 2024-10-28: | ||
# | ||
# * Initial version. | ||
|
||
# nocov start | ||
|
||
#' Use Font Awesome icons as favicons | ||
#' | ||
#' Generate the html necessary to use a Font Awesome icon as the favicon (the | ||
#' icon that appears on browser tabs) for a Shiny app or other HTML document. | ||
#' | ||
#' @return A `shiny.tag` (see [htmltools::tag()]) that can be used to embed a | ||
#' favicon in a Shiny app or other HTML document. | ||
#' @noRd | ||
favawesome_icon <- function(name, ...) { | ||
fav_base64 <- .standalone_fav_encode(name, ...) | ||
fav_href <- .standalone_fav_as_href(fav_base64) | ||
htmltools::tags$head( | ||
htmltools::tags$link(rel = "icon", type = "image/png", href = fav_href) | ||
) | ||
} | ||
|
||
#' Load Font Awesome icon and encode | ||
#' | ||
#' @return A base64-encoded character vector representing the icon png. | ||
#' @noRd | ||
.standalone_fav_encode <- function(name, ...) { | ||
jsonlite::base64_enc( | ||
rsvg::rsvg_png( | ||
charToRaw( | ||
fontawesome::fa(name, ...) | ||
), | ||
width = 32, | ||
height = 32 | ||
) | ||
) | ||
} | ||
|
||
#' Add data URI prefix to base64-encoded icon | ||
#' | ||
#' @param fav_base64 A base64-encoded character vector generated by | ||
#' `.fav_encode()`. | ||
#' | ||
#' @return The base64-encoded icon with the data URI prefix. | ||
#' @noRd | ||
.standalone_fav_as_href <- function(fav_base64) { | ||
paste0("data:image/png;base64,", fav_base64) | ||
} | ||
|
||
# nocov end |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.