Skip to content
Snippets Groups Projects
Commit d9306b69 authored by jens.preussner's avatar jens.preussner :ghost:
Browse files

Added support for links, source and social media.

See merge request !12
parents 50efbb2a a17a6e30
No related branches found
No related tags found
1 merge request!12Navbar items
Pipeline #129989 failed
...@@ -18,6 +18,7 @@ Imports: ...@@ -18,6 +18,7 @@ Imports:
flexdashboard, flexdashboard,
yaml, yaml,
assertive.sets, assertive.sets,
assertive.types,
rmarkdown, rmarkdown,
stringr, stringr,
glue, glue,
......
...@@ -3,11 +3,15 @@ ...@@ -3,11 +3,15 @@
export("%>%") export("%>%")
export("author<-") export("author<-")
export("datadir<-") export("datadir<-")
export("embed_source<-")
export("interactivity<-") export("interactivity<-")
export("social_links<-")
export("source<-")
export("theme<-") export("theme<-")
export("title<-") export("title<-")
export(add_colormap) export(add_colormap)
export(add_component) export(add_component)
export(add_link)
export(add_page) export(add_page)
export(add_to_sidebar) export(add_to_sidebar)
export(assemble) export(assemble)
...@@ -17,11 +21,14 @@ export(embed_var) ...@@ -17,11 +21,14 @@ export(embed_var)
export(i2dashboard) export(i2dashboard)
export(interactivity) export(interactivity)
export(remove_page) export(remove_page)
export(social_links)
export(source)
export(theme) export(theme)
export(title) export(title)
exportClasses(i2dashboard) exportClasses(i2dashboard)
exportMethods(add_colormap) exportMethods(add_colormap)
exportMethods(add_component) exportMethods(add_component)
exportMethods(add_link)
exportMethods(add_page) exportMethods(add_page)
exportMethods(add_to_sidebar) exportMethods(add_to_sidebar)
exportMethods(assemble) exportMethods(assemble)
......
...@@ -45,4 +45,22 @@ setGeneric("theme<-", function(dashboard, value) standardGeneric("theme<-")) ...@@ -45,4 +45,22 @@ setGeneric("theme<-", function(dashboard, value) standardGeneric("theme<-"))
setGeneric("datadir", function(dashboard) standardGeneric("datadir")) setGeneric("datadir", function(dashboard) standardGeneric("datadir"))
#' @export #' @export
setGeneric("datadir<-", function(dashboard, value) standardGeneric("datadir<-")) setGeneric("datadir<-", function(dashboard, value) standardGeneric("datadir<-"))
\ No newline at end of file
#' @export
setGeneric("social_links", function(dashboard) standardGeneric("social_links"))
#' @export
setGeneric("social_links<-", function(dashboard, value) standardGeneric("social_links<-"))
#' @export
setGeneric("embed_source<-", function(dashboard, value) standardGeneric("embed_source<-"))
#' @export
setGeneric("source", function(dashboard) standardGeneric("source"))
#' @export
setGeneric("source<-", function(dashboard, value) standardGeneric("source<-"))
#' @export
setGeneric("add_link", function(dashboard, ...) standardGeneric("add_link"))
\ No newline at end of file
...@@ -19,12 +19,24 @@ setMethod("assemble", "i2dashboard", function(dashboard, pages = names(dashboard ...@@ -19,12 +19,24 @@ setMethod("assemble", "i2dashboard", function(dashboard, pages = names(dashboard
saveRDS(dashboard@colormaps, file = file.path(dashboard@datadir, colormap_id)) saveRDS(dashboard@colormaps, file = file.path(dashboard@datadir, colormap_id))
} }
# Hack to proper source and social
if (dashboard@source == "") {
source <- NULL
} else {
source <- dashboard@source
}
if (dashboard@social == "") {
social <- NULL
} else {
social <- dashboard@social
}
# Add YAML header # Add YAML header
options(ymlthis.rmd_body = "") options(ymlthis.rmd_body = "")
ymlthis::yml(date = F) %>% ymlthis::yml(date = F) %>%
ymlthis::yml_title(dashboard@title) %>% ymlthis::yml_title(dashboard@title) %>%
ymlthis::yml_author(dashboard@author) %>% ymlthis::yml_author(dashboard@author) %>%
ymlthis::yml_output(flexdashboard::flex_dashboard(theme = !!dashboard@theme)) %>% ymlthis::yml_output(flexdashboard::flex_dashboard(theme = !!dashboard@theme, social = !!social, source = !!source, navbar = !!dashboard@navbar)) %>%
{if(dashboard@interactive) ymlthis::yml_runtime(., runtime = "shiny") else .} %>% {if(dashboard@interactive) ymlthis::yml_runtime(., runtime = "shiny") else .} %>%
ymlthis::use_rmarkdown(path = tmp_document, include_body = FALSE, quiet = TRUE, open_doc = FALSE) ymlthis::use_rmarkdown(path = tmp_document, include_body = FALSE, quiet = TRUE, open_doc = FALSE)
......
...@@ -77,3 +77,83 @@ setMethod("datadir<-", "i2dashboard", function(dashboard, value) { ...@@ -77,3 +77,83 @@ setMethod("datadir<-", "i2dashboard", function(dashboard, value) {
dashboard@datadir <- value dashboard@datadir <- value
dashboard dashboard
}) })
#' Get/set the links to be shown for sharing on social media. Any of the following services are allowed: “facebook”, “twitter”, “google-plus”, “linkedin”, and “pinterest”. You can also specify “menu” to provide a generic sharing drop-down menu that includes all of the services.
#'
#' @param dashboard A \linkS4class{i2dash::i2dashboard}.
#' @param value The value of the desired property.
#'
#' @name i2dashboard-class
#' @rdname i2dashboard-class
setMethod("social_links", "i2dashboard", function(dashboard) dashboard@social_links)
#' @name i2dashboard-class
#' @rdname i2dashboard-class
setMethod("social_links<-", "i2dashboard", function(dashboard, value) {
i <- intersect(tolower(value), c("facebook", "twitter", "google-plus", "linkedin", "pinterest", "menu"))
if (length(i) > 0) {
dashboard@social <- i
}
dashboard
})
#' Get/set the embedding of the source code of the i2dashboard. Can either be a URL pointing to where the source code can be found online or whether or not to embed the source code into the document.
#'
#' @param dashboard A \linkS4class{i2dash::i2dashboard}.
#' @param value The value of the desired property. A URL pointing to where the source code can be found online.
#'
#' @name i2dashboard-class
#' @rdname i2dashboard-class
setMethod("source", "i2dashboard", function(dashboard) dashboard@source)
#' @name i2dashboard-class
#' @rdname i2dashboard-class
setMethod("source<-", "i2dashboard", function(dashboard, value) {
dashboard@source <- tolower(as.character(value))
dashboard
})
#' @name i2dashboard-class
#' @rdname i2dashboard-class
setMethod("embed_source<-", "i2dashboard", function(dashboard, value) {
if(value) {
dashboard@source <- "embed"
} else {
dashboard@source <- ""
}
dashboard
})
#' Add a link to the navigation bar.
#'
#' @param dashboard A \linkS4class{i2dash::i2dashboard}.
#' @param href The target of the link.
#' @param title The link title.
#' @param icon An optional link icon (see https://rmarkdown.rstudio.com/flexdashboard/using.html#icon-sets)
#' @param align Optional argument that can be “left” or “right” (defaults = “right”) defining the alignment of the links in the navigation bar
#' @param target An optional target (e.g. "_blank")
#'
#' @rdname i2dashboard-methods
#' @export
setMethod("add_link", "i2dashboard", function(dashboard, href, title = NULL, icon = NULL, align = c("right","left"), target = NULL) {
align <- match.arg(align)
if(is.null(title) & is.null(icon)) {
warning("Both, title and icon, cannot be NULL when adding a link.")
return(dashboard)
}
# Workaround for NULL values
if(is.null(icon)) {
icon <- ""
}
if(is.null(title)) {
title = ""
}
if(is.null(target)) {
target = ""
}
dashboard@navbar <- append(dashboard@navbar, list(list("href" = href, "title" = title, "icon" = icon, "align" = align, "target" = target)))
dashboard
})
...@@ -9,6 +9,9 @@ ...@@ -9,6 +9,9 @@
#' @slot pages A list of dashboard pages #' @slot pages A list of dashboard pages
#' @slot sidebar Content of the global sidebar #' @slot sidebar Content of the global sidebar
#' @slot colormaps A named list with color mappings. #' @slot colormaps A named list with color mappings.
#' @slot source Either a logical value describing whether the source code should be embeded through an item in the navigation bar or a link to a URL where the source code can be found online.
#' @slot social A vector with any number of the following services: “facebook”, “twitter”, “google-plus”, “linkedin”, and “pinterest”. You can also specify “menu” to provide a generic sharing drop-down menu that includes all of the services.
#' @slot navbar A list of links in the navigation bar (see https://rmarkdown.rstudio.com/flexdashboard/using.html#navigation_bar).
#' #'
#' @return An i2dashboard object. #' @return An i2dashboard object.
#' #'
...@@ -25,14 +28,19 @@ setClass("i2dashboard", ...@@ -25,14 +28,19 @@ setClass("i2dashboard",
file = "character", file = "character",
pages = "list", pages = "list",
sidebar = "character", sidebar = "character",
colormaps = "list" colormaps = "list",
source = "character",
social = "character",
navbar = "list"
), ),
prototype=list( prototype=list(
title = "i2dashboard", title = "i2dashboard",
interactive = FALSE, interactive = FALSE,
theme = "yeti", theme = "yeti",
datadir = file.path(getwd(), "report-data"), datadir = file.path(getwd(), "report-data"),
pages = list(default = list(title = "Default page", layout = "default", menu = NULL, components = list(), sidebar = NULL, max_components = Inf)) pages = list(default = list(title = "Default page", layout = "default", menu = NULL, components = list(), sidebar = NULL, max_components = Inf)),
source = "",
social = ""
) )
) )
......
...@@ -23,11 +23,21 @@ ...@@ -23,11 +23,21 @@
\S4method{datadir}{i2dashboard}(dashboard) \S4method{datadir}{i2dashboard}(dashboard)
\S4method{datadir}{i2dashboard}(dashboard) <- value \S4method{datadir}{i2dashboard}(dashboard) <- value
\S4method{social_links}{i2dashboard}(dashboard)
\S4method{social_links}{i2dashboard}(dashboard) <- value
\S4method{source}{i2dashboard}(dashboard)
\S4method{source}{i2dashboard}(dashboard) <- value
\S4method{embed_source}{i2dashboard}(dashboard) <- value
} }
\arguments{ \arguments{
\item{dashboard}{A \linkS4class{i2dash::i2dashboard}.} \item{dashboard}{A \linkS4class{i2dash::i2dashboard}.}
\item{value}{The value of the desired property.} \item{value}{The value of the desired property. A URL pointing to where the source code can be found online.}
} }
\description{ \description{
Get/set the interactivity of the i2dashboard. Get/set the interactivity of the i2dashboard.
...@@ -39,4 +49,8 @@ Get/set the author of the i2dashboard. ...@@ -39,4 +49,8 @@ Get/set the author of the i2dashboard.
Get/set the theme of the i2dashboard. Get/set the theme of the i2dashboard.
Get/set the datadir of the i2dashboard. Get/set the datadir of the i2dashboard.
Get/set the links to be shown for sharing on social media. Any of the following services are allowed: “facebook”, “twitter”, “google-plus”, “linkedin”, and “pinterest”. You can also specify “menu” to provide a generic sharing drop-down menu that includes all of the services.
Get/set the embedding of the source code of the i2dashboard. Can either be a URL pointing to where the source code can be found online or whether or not to embed the source code into the document.
} }
% Generated by roxygen2: do not edit by hand % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/assemble.R, R/colormap.R, R/pages.R, % Please edit documentation in R/assemble.R, R/colormap.R, R/get_set.R,
% R/sidebar.R % R/pages.R, R/sidebar.R
\name{assemble,i2dashboard-method} \name{assemble,i2dashboard-method}
\alias{assemble,i2dashboard-method} \alias{assemble,i2dashboard-method}
\alias{add_colormap,i2dashboard-method} \alias{add_colormap,i2dashboard-method}
\alias{add_link,i2dashboard-method}
\alias{add_page,i2dashboard-method} \alias{add_page,i2dashboard-method}
\alias{remove_page,i2dashboard-method} \alias{remove_page,i2dashboard-method}
\alias{add_to_sidebar,i2dashboard-method} \alias{add_to_sidebar,i2dashboard-method}
...@@ -20,6 +21,15 @@ ...@@ -20,6 +21,15 @@
\S4method{add_colormap}{i2dashboard}(dashboard, map, name) \S4method{add_colormap}{i2dashboard}(dashboard, map, name)
\S4method{add_link}{i2dashboard}(
dashboard,
href,
title = NULL,
icon = NULL,
align = c("right", "left"),
target = NULL
)
\S4method{add_page}{i2dashboard}( \S4method{add_page}{i2dashboard}(
dashboard, dashboard,
page, page,
...@@ -58,10 +68,18 @@ ...@@ -58,10 +68,18 @@
\item{name}{A name for the color mapping.} \item{name}{A name for the color mapping.}
\item{page}{The name of the page to which add the sidebar.} \item{href}{The target of the link.}
\item{title}{The title of the page to be added.} \item{title}{The title of the page to be added.}
\item{icon}{An optional link icon (see https://rmarkdown.rstudio.com/flexdashboard/using.html#icon-sets)}
\item{align}{Optional argument that can be “left” or “right” (defaults = “right”) defining the alignment of the links in the navigation bar}
\item{target}{An optional target (e.g. "_blank")}
\item{page}{The name of the page to which add the sidebar.}
\item{layout}{The page layout (see below).} \item{layout}{The page layout (see below).}
\item{menu}{The name of the menu, under which the page should appear.} \item{menu}{The name of the menu, under which the page should appear.}
......
...@@ -44,5 +44,11 @@ Create a new i2dashboard object. ...@@ -44,5 +44,11 @@ Create a new i2dashboard object.
\item{\code{sidebar}}{Content of the global sidebar} \item{\code{sidebar}}{Content of the global sidebar}
\item{\code{colormaps}}{A named list with color mappings.} \item{\code{colormaps}}{A named list with color mappings.}
\item{\code{source}}{Either a logical value describing whether the source code should be embeded through an item in the navigation bar or a link to a URL where the source code can be found online.}
\item{\code{social}}{A vector with any number of the following services: “facebook”, “twitter”, “google-plus”, “linkedin”, and “pinterest”. You can also specify “menu” to provide a generic sharing drop-down menu that includes all of the services.}
\item{\code{navbar}}{A list of links in the navigation bar (see https://rmarkdown.rstudio.com/flexdashboard/using.html#navigation_bar).}
}} }}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment