Flexdashboards

We can create dashboards using the flexdashboard package by specifying flex_dashboard as the output format in the R Markdown YAML. There are many possible outputs you can create. For now, below is the default dashboard template in R Studio – if you install flexdashboard, you can use File > New File > R Markdown > From Template to create a new .Rmd file with the structure below.

This is an example outline of a dashboard:

It has a sidebar, and two columns with spaces for plots. Just as in any RMarkdown document, you can input text and code and it will be rendered. In this case, it is rendered into a dashboard with the information in the pre-specified spaces.

---
title: "Flex Dashboard"
output: 
  flexdashboard::flex_dashboard:
    orientation: columns
    vertical_layout: fill
---



Column {.sidebar}
-----------------------------------------------------------------------



Column {data-width=650}
-----------------------------------------------------------------------

### Chart A



Column {data-width=350}
-----------------------------------------------------------------------

### Chart B



### Chart C

Layout info

You can have a single page, additional tabs, and multiple pages

In the YAML you will enter vertical_layout: fill or vertical_layout: scroll, which controls how plots will fill the screen. They will either zoom to fill, or maintain dimensions and allow scrolling. Play around to decide which is right for you

You can have row or column alignment, controlled by {data-orientation=columns} or {data-orientation=rows}

Tabs are entered in a row or column with {.tabset} or {.tabset .tabset-fade}

When creating multiple pages, use the following to designate breaks:

Page 1
=====================================  
    
Column 
-------------------------------------
    
### Chart 1


Page 2 {data-orientation=rows}
=====================================     
   
Row {data-height=600}
-------------------------------------

### Chart 1




### title makes the caption

#### will make headers

There are more info and examples here or you can look here for examples and try to understand their codes

My examples

Be sure to check out the source code for the next two parts of the tutorial.

The first dashboard is a static flexdashboard. The plots are made with ggplotly so that when you hover, information appears.

The second dashboard adds runtime: shiny and creates the plots with Render statements. It is also hosted on shiny to allow R to run in the background and power the widgets. Read more about hosting in the “optional” tutorial.

Additional Resources

flexdashboard

  • flex dashboards can be static or made interactive by using runtime: shiny

flex dashboard guide

layout guide

dashboard chapter in markdown book

plot.ly

  • plot.ly creates interactive plots

  • you can also wrap ggplot objects in ggplotly to make them interactive

plot.ly guide

cheatsheet

ggplotly