Skip to content
Snippets Groups Projects

fixed sidebar

Merged arsenij.ustjanzew requested to merge sidebar into master
1 unresolved thread
Files
4
+ 16
9
@@ -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, ...))
if(is.list(component)) {
assertive.sets::is_subset(c("appendix", "component", "sidebar"), names(component))
@@ -110,18 +114,21 @@ render_text <- function(file, title = NULL, raw = FALSE) {
#' @param image_alt_text The alt text of the image.
#' @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 width Width defined with CSS in the HTML img-tag.
#' @param height Height defined with CSS in the HTML img-tag.
#'
#' @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)
}
content <- glue::glue(as.character(
htmltools::img(
src = image,
alt = image_alt_text,
style = paste0('height:', height, ';width:', width)
)),as.character(htmltools::br()))
if(raw) return(content)
knitr::knit_expand(file = system.file("templates", "component.Rmd", package = "i2dash"),
Loading