Skip to content
Snippets Groups Projects

fixed sidebar

Merged arsenij.ustjanzew requested to merge sidebar into master
1 unresolved thread
Files
4
+ 13
8
@@ -16,13 +16,17 @@
#' @param page The name of the page to add the component to.
#' @param component The name of a function or a path to a file.
#' @param copy Whether or not to copy images to \code{dashboard@datadir}.
#' @param image_width Image width in pixel.
#' @param image_height Image width in pixel.
#' @param image_alt_text Alternate text for an image.
#' @param image_description Image description shown below the image.
#' @param ... Additional parameters passed to the components render function.
#'
#' @rdname add-component
#' @export
setMethod("add_component",
signature = signature(dashboard = "i2dashboard", component = "character"),
function(dashboard, component, page = "default", copy = FALSE, ...) {
function(dashboard, component, page = "default", copy = FALSE, image_width = "100%", image_height = "auto", image_alt_text = NULL, image_description = NULL, ...) {
# Logic to guess intended usage
mode <- "function"
if(stringr::str_detect(tolower(component), "\\.[md|txt]+$")) {
@@ -61,7 +65,7 @@ setMethod("add_component",
component <- switch(mode,
"function" = eval_function(dashboard, ...),
"text" = render_text(component, ...),
"image" = render_image(component, ...))
"image" = render_image(component, width = image_width, height = image_height, image_alt_text = image_alt_text, description = image_description, ...))
if(is.list(component)) {
assertive.sets::is_subset(c("appendix", "component", "sidebar"), names(component))
@@ -111,17 +115,18 @@ render_text <- function(file, title = NULL, raw = FALSE) {
#' @param title The components title.
#' @param raw Whether or not to emit solely the markdown image code.
#' @param width The width of the image.
#' @param height The height of the image
#' @param description An image description below the image.
#'
#' @return A character string containing the evaluated component
render_image <- function(image, image_alt_text = NULL, title = NULL, raw = FALSE, width = NULL) {
render_image <- function(image, image_alt_text = NULL, title = NULL, raw = FALSE, width = "100%", height = "auto", description = NULL) {
if(is.null(image_alt_text)) {
image_alt_text <- image
}
if(!is.null(width)){
content <- glue::glue("<img src={image} width={width}/></br>\n", image_alt_text = image_alt_text, image = image, width = width)
} else {
content <- glue::glue("![{image_alt_text}]({image})\n", image_alt_text = image_alt_text, image = image)
}
if(is.numeric(width)) width <- paste0(width,"px")
if(is.numeric(height)) height <- paste0(height,"px")
content <- paste0("<img src='",image,"' alt='",image_alt_text,"' style='width:",width,"; height:",height,"'/></br>\n")
if(!is.null(description)) content <- paste0(content,"*",description,"*\n\n")
if(raw) return(content)
knitr::knit_expand(file = system.file("templates", "component.Rmd", package = "i2dash"),
Loading