Skip to content
Snippets Groups Projects
Commit c5938018 authored by arsenij.ustjanzew's avatar arsenij.ustjanzew
Browse files

written some descriptions for adding text, images or a colormap to the dashboard.

parent b1e25fbe
No related branches found
No related tags found
1 merge request!8Vignette: i2dash introduction
Pipeline #110726 failed
......@@ -37,7 +37,7 @@ setMethod("add_component",
mode <- "image"
}
# Create page
# validate "page" input
name <- .create_page_name(page)
if (!(name %in% names(dashboard@pages))) {
warning(sprintf("i2dashboard dashboard does not contain a page named '%s'", name))
......
......@@ -5,6 +5,7 @@
#' @param package The name of the R package that defines the class(object).
#' @param page The name of the page to add the object to.
#' @param title An optional component title.
#' @export
add_vis_object <- function(dashboard, object, package, page = "default", title = NULL, ...){
sanitised_page <- i2dash:::.create_page_name(page)
if (!(sanitised_page %in% names(dashboard@pages))) {
......
......@@ -111,11 +111,13 @@ interactivity(dashboard) <- TRUE
The next step is to add pages to the `i2dashboard` object. This is done by the function `add_page()`. The argument `page` sets an unique identifier for this page. This id is later used to define to which page the component should be added and which pages should be assembled into the final dashboard or be ignored. The `title` defines a title of the page, which is shown as a top level tab on the navigation bar. With `menu` you can group several pages under one top level tab, that provides a dwop down menu containing the pages.
```{r}
dashboard <- i2dash::add_page(dashboard = dashboard,
page = "page1",
title = "Page title 1",
layout = "focal_left",
menu = NULL)
dashboard <- i2dash::add_page(
dashboard = dashboard,
page = "page1",
title = "Page title 1",
layout = "focal_left",
menu = NULL
)
```
```{r fig1, echo=FALSE, out.width='100%', fig.cap="\\label{fig:fig1} Example of a navigation bar."}
......@@ -178,29 +180,36 @@ object_3 <- leaflet() %>%
# Add the objects as components to the page 'p1' of the i2dashboard object 'dashboard'.
# The adding order of the components in the 'focal_left' layout is shown above. If we want, that the leaflet object is displayed on the left side, we need to add it first.
dashboard <- i2dash::add_component(dashboard = dashboard,
component = object_3,
page = "page1",
title = "leaflet object")
dashboard <- i2dash::add_component(
dashboard = dashboard,
component = object_3,
page = "page1",
title = "leaflet object"
)
dashboard <- i2dash::add_component(dashboard = dashboard,
component = object_1,
page = "page1",
title = "plotly object")
dashboard <- i2dash::add_component(
dashboard = dashboard,
component = object_1,
page = "page1",
title = "plotly object"
)
dashboard <- i2dash::add_component(dashboard = dashboard,
component = object_2,
page = "page1",
title = "ggplot2 object")
dashboard <- i2dash::add_component(
dashboard = dashboard,
component = object_2,
page = "page1",
title = "ggplot2 object"
)
# Example of the use of a function from an extension package for i2dash (i2dash.scrnaseq).
# This component will be added to the 'default' page.
library(i2dash.scrnaseq)
dashboard <- i2dash::add_component(dashboard = dashboard,
component = "i2dash.scrnaseq::scatterplot", # Function to create the page or component.
x = data.frame(mtcars$mpg),
y = data.frame(mtcars$wt),
title = "Test i2dash.scrnaseq"
dashboard <- i2dash::add_component(
dashboard = dashboard,
component = "i2dash.scrnaseq::scatterplot", # Function to create the page or component.
x = data.frame(mtcars$mpg),
y = data.frame(mtcars$wt),
title = "Test i2dash.scrnaseq"
)
```
......@@ -241,7 +250,6 @@ library(magrittr)
library(wordcloud2)
library(kableExtra)
# Create objects
#
# Example for a htmlwidget based package:
......@@ -254,33 +262,65 @@ kable(mtcars[1:5, 1:6]) %>%
dashboard <- i2dash::add_vis_object(
dashboard = dashboard,
object = obj_1,
package = "wordcloud2",
# provide the package
package = "wordcloud2", # provide the package
title = "wordcloud2 object"
)
dashboard <- i2dash::add_vis_object(
dashboard = dashboard,
object = obj_2,
package = "kableExtra",
# provide the package
package = "kableExtra", # provide the package
title = "kableExtra object"
)
# The objects are added to the 'default' page
```
## Adding Markdown and images
## Adding text and images
Also, it is possible to include text or image files into the component containers. The function `add_component` tries to guess the intended usage by applying regular expressions to the argument `component`. If the argument `component` is a valid function name, the function will be called and its return value is used as component content. In the case the argument `component` ends with `.md` or `.txt`, the function will try to open a file and use its content as the components content. If the argument `component` matches `.[png|jpg|jpeg|gif]`, the function will try to include an image as the components content.
## Adding a document wide colormap
i2dash provides the possibility to use colormaps that are applied document wide. If the chart of the component can handle colormaps of i2dash, the groups definded by th grouping factors will be colored by the values from the colormap. The extension package `i2dash.scrnaseq` contains several plots (violinplot, boxplot, barplot, scatterplot etc.), among other things, which can use the user defined colormaps and apply them to the groupings. In this case the name of the colormap shoud be identical with the column name that contatins the factors. In the following example, it is shown how to add a colormap to the i2dashboard and how to use the boxplot function from the `i2dash.scrnaseq` package:
```{r, eval=F}
# load the data
df <- mtcars
df$cyl <- as.factor(df$cyl)
# create colormap
colormap1 <- c("4"="red", "6"="green", "8"="blue")
# add colormap to the i2dashboard
dashboard <- i2dash::add_colormap(
dashboard = dashboard,
map = colormap1,
name = "cyl"
)
# add comonent that can handle the colormaps
library(i2dash.scrnaseq)
dashboard <- i2dash::add_component(
dashboard = dashboard,
component = "i2dash.scrnaseq::boxplot",
x = data.frame(df$mpg, df$wt),
group_by = data.frame(df$cyl),
title = "Boxplot"
)
```
## Assembling pages {#assembling}
After each step of adding a new component or page to the `i2dashboard` object, it is possible to create the final output R markdown file by assembling the dashboard with `assemble()`. The optional argument `pages` accepts a single character or a character vector with the page names that should be included in the final dashboard. By default all pages are assebled.
After each step of adding a new component or page to the `i2dashboard` object, it is possible to create the final output R markdown file by assembling the dashboard with `assemble()`. The optional argument `pages` accepts a single character or a character vector with the page names that should be included in the final dashboard. By default all pages will be assembled. Often,it is not desired to assemble the dashboard with the default page of the i2dashboard object. With the parameter `exclude` the user can provide a single character or a vector with the page names that should be excluded from the final dashboard document. Furthermore, it is possible to immediately render the document by providing the `render` parameter.
```{r}
dashboard
i2dash::assemble(dashboard = dashboard,
file = "MyDashboard.Rmd",
pages = "page1")
i2dash::assemble(
dashboard = dashboard,
file = "MyDashboard.Rmd",
pages = "page1"
)
```
# Additional information
......
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