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 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.
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:
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.