Created
January 8, 2024 19:09
-
-
Save tomsing1/86914347f938c72bcd2c84b73975091f to your computer and use it in GitHub Desktop.
Create an image tag pointing to a random picture from Lorem Picsum
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
#' Create an image tag with an example image | |
#' | |
#' @param width Scalar integer, the width of the image | |
#' @param height Scalar integer, the height of the image | |
#' @param title Scalar character, the title of the image | |
#' @return A `shiny.tag` with the URL to a random image from | |
#' [Lorem Picsum](https://picsum.photos/) | |
#' @export | |
#' @importFrom htmltool tags | |
#' @importFrom checkmate assert_count assert_character | |
#' @examples | |
#' image_placeholder(100, 200) | |
image_placeholder <- function(width = 200, height = 300, | |
title = "Example Image") { | |
checkmate::assert_count(width) | |
checkmate::assert_count(height, null.ok = TRUE) | |
checkmate::assert_character(title) | |
url <- ifelse(is.null(height), | |
sprintf("https://picsum.photos/%s", width), | |
sprintf("https://picsum.photos/%s/%s", width, height)) | |
htmltools::tags$img(src=url, title=title, width=width, | |
height=ifelse(is.null(height), width, height)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment