Content can be added to the dashboards pages, the sidebar or the navigation bar.

add_component(dashboard, component, ...)

add_to_sidebar(dashboard, component, ...)

add_colormap(dashboard, ...)

add_link(dashboard, ...)

# S4 method for i2dashboard,character
add_component(dashboard, component, page = "default", copy = FALSE, ...)

# S4 method for i2dashboard,`function`
add_component(dashboard, component, page = "default", ...)

# S4 method for i2dashboard,gg
add_component(dashboard, component, page = "default", ...)

# S4 method for i2dashboard,gt_tbl
add_component(dashboard, component, page = "default", ...)

# S4 method for i2dashboard,kableExtra
add_component(dashboard, component, page = "default", ...)

# S4 method for i2dashboard,Heatmap
add_component(dashboard, component, page = "default", ...)

# S4 method for i2dashboard,ANY
add_component(dashboard, component, page = "default", ...)

# S4 method for i2dashboard
add_link(
  dashboard,
  href,
  title = NULL,
  icon = NULL,
  align = c("right", "left"),
  target = NULL
)

# S4 method for i2dashboard
add_colormap(dashboard, map, name)

# S4 method for i2dashboard,character
add_to_sidebar(
  dashboard,
  component,
  page = "default",
  global = FALSE,
  copy = FALSE,
  ...
)

# S4 method for i2dashboard,`function`
add_to_sidebar(
  dashboard,
  component,
  page = "default",
  global = FALSE,
  copy = FALSE,
  ...
)

Arguments

dashboard

A i2dashboard.

component

An R object, function, or string.

...

Additional parameters passed to the components render function. In case of an image, parameters height and width can be used to define the dimensions of the image with CSS or provide an alternative text with image_alt_text.

page

The name of the page to add the component or sidebar to.

copy

Whether or not to copy images to dashboard@datadir.

href

The target of the link.

title

The link title.

icon

An optional link icon (see https://rmarkdown.rstudio.com/flexdashboard/using.html#icon-sets)

align

Optional argument that can be “left” or “right” (defaults = “right”) defining the alignment of the links in the navigation bar

target

An optional target (e.g. "_blank")

map

A character vector containing colors and possible the levels they map to (as names).

name

A name for the color mapping.

global

Whether or not to add the content to the global sidebar.

Value

Returns the modified i2dashboard object.

  • 'add_component()' extends the list of components of the respective page, stored in the 'pages' slot, by an R Markdown string containing the provided content.

  • 'add_to_sidebar()' extends either the 'sidebar' slot or the 'sidebar' entry of a single page by an R Markdown string containing the provided content.

  • 'add_link()' extends the 'navbar' slot by a list of link properties.

  • 'add_colormap()' extends the 'colormaps' slot by the new color mapping.

If something went wrong during the addition, the unmodified i2dashboard object is returned.

Details

The options to add content in detail:

  • 'add_component()' adds content to a page of the dashboard by evaluating a function, or by including an object, a text or image file.

  • 'add_to_sidebar()' adds content to the dashboards global sidebar or to a pages local sidebar.

  • 'add_link()' adds a link to the navigation bar.

  • 'add_colormap()' adds a global color mapping to the dashboards colormaps.

The mechanism to add different types of content to a dashboards page or sidebar depends on the class of the object passed to the function 'add_component()' or 'add_to_sidebar()':

  • A function will be evaluated and its return value is used as content.

  • A string that ends with .md or .txt will be used to open a file and use its content.

  • A string that ends with \.[png|jpg|jpeg|gif] will be used to include an image as content.

  • An R object (e.g. an 'htmlwidget') will be included if a suitable signature method is implemented.

Examples

library(magrittr)
i2dashboard() -> dashboard
myFunction <- function(dashboard) paste0("### Generate component\n\n",
    "Lorem ipsum dolor sit amet\n")

dashboard %<>% add_component(component = myFunction)
dashboard %<>% add_component(component = plotly::plot_ly(mtcars, x=~wt, y=~hp),
    title = "Include htmlwidget")
# \donttest{
  dashboard %<>% add_component(component = "sample.txt", title = "Include text")
  dashboard %<>% add_component(component = "sample.jpg", title = "Include image")
# }

dashboard %<>% add_to_sidebar(component = myFunction)
# \donttest{
  dashboard %<>% add_to_sidebar(component = "sample.txt", package="i2dash")
  dashboard %<>% add_to_sidebar(component = "sample.jpg", package="i2dash")
# }

colors <- c("l1" = "#F7FCFD", "l2" ="#E5F5F9", "l3" = "#CCECE6")
dashboard %<>% add_colormap(map = colors, name = "test")

dashboard %<>% add_link(href = "www.sample_url.net", title = "MyLink", align = "left")