Creating dashboards using "flexdashboard" R package
Creating a dashboard is an attractive way to visualize different groups of related data. To setup a dashboard we can use the R package flexdashboard
.
First, setup the orientation of the dashboard in YML header. The default orientation is columns, which shows individual charts stacked vertically within each column. To setup the orientation row-wise specify
orientation: rows
option in YML header.Similarly, we can display several components in different windows using a
tabset
. To add a tabset layout as a row or column we have to add the{.tabset}
attribute to the section heading. The widths and heights of rows and columns can be set by usingdata-width
anddata-height
attributes when we define a row or a column.In the dashboard, we can include a wide variety of components.
- One such component is
htmlwidgets
, for which there are over 30 packages on CRAN. Some of the available htmlwidgets are Leaflet, dygraphs, Plotly, rbokeh, Highcharter, and visNetwork. For larger data sets, use standard R graphics instead of htmlwidgets. - We can use any chart created with standard R graphics (base, lattice, grid, etc.) with
flexdashboard
. - Tabular data can be included within flexdashboards as a simple tabular display which is suitable for smaller number of observations,or as a DataTable. For simple tabular display, we can use the
knitr::kable
function to display the dataset. For DataTable, we can use DT package to display matrices or data frames as interactive HTML tables. - We can also use the valueBox function to display single values along with a title and optional icon, and gauge function to display values on a meter within a specified range.
- Including a navigation bar is also possible to the
flexdashboard
. By default it shows document’s title, author and date. In addition to that, we can add custom links and social links as well. - If we need to include additional text in the dashboard, we can add the content at the top of the page before dashboard sections are introduced, or we can add a dashboard sections which don’t contains charts, but only text, images equations etc.
If We expect to divide the dashboard into multiple pages, define a page by adding a level 1 markdown header (
==================
). For each page we can have different page orientation by adding thedata-orientation
attribute to the header of the page. e.g.page 1 {data-orientation=rows}
To access a page via a navigation bar menu, we can use the
data-navmenu
attribute as below:Page 1 {data-navmenu="Menu 1"}
- Also, we can link different pages or hide a page using options
[Page Two](#page-2)
andPage 4 {.hidden}
, respectively. Further, we can add an icon to the navigation menu for a page using the
data-icon
attribute.
e.g.Page 2 {data-icon="fa-list"}
The icons can be selected from three different icon sets, Font Awesome, Ionicons, and Bootstrap Glyphicons.Using
flexdashboard
package we can also create a storyboard layout. To create a storyboard, add thestoryboard: true
option in the YML header. Then include a set of level 3 (###
) dashboard components as a frame which is a navigation caption.
e.g.### Frame 1
Further, we can layout one or more pages of a dashboard as storyboards and other pages as usual row and column layout of a dashboard. In this case, we have to exclude the
storyboard: true
option from YML header, and add the{.storyboard}
attribute to pages that we expect to lay out as storyboards.
Some flexdashboards examples are shown here.
More details