1. Anatomy of a flexdashboard
Now we're going to talk about the basics of how a flexdashboard is put together.
2. R Markdown: the header
The little piece of magic that turns R Markdown into a flexdashboard is in the header. Every R Markdown file starts with a header, and the key part for us is the output line. If you’ve used R Markdown before, you may have noticed that the output was set to html_document, or perhaps pdf_document. This option determines how everything in your R Markdown file is interpreted, and what type of output is produced when you knit the document.
3. Turning R Markdown into a flexdashboard
So you might have guessed how we make our R Markdown file become a flexdashboard: we change the output type to flex_dashboard. You’ll usually see this as output: flexdashboard::flex_dashboard, which makes it extra clear that this output option comes with the flexdashboard R package. With this option set, your R Markdown file will be interpreted as flexdashboard syntax.
4. A flexdashboard is made of charts ...
A flexdashboard is made of charts. Every chart fills one box in the dashboard layout.
5. A flexdashboard is made of charts ...
The way to indicate a chart in your R Markdown file is with a triple pound sign. Everything below one of these and above the next will be included in a single chart. Usually this is a single R chunk, but it can also include text. The title of the chart can be included on the same line as the triple pound sign.
6. ... and charts are arranged in columns
Charts are arranged in columns. Every chart is in exactly one column, but a column can contain multiple charts. You can create a dashboard without specifying columns, and all charts will stack up in a single column by default. However, usually you’ll want to specify the columns directly. Columns are created using a series of 14 or more dashes in flexdashboard syntax. All charts between one column header and the next will be laid out in that column. You can add a name for the column and options (which we’ll talk about later) on the line above the dashes, but the name will not appear anywhere in your dashboard. A specific name might be helpful for you, or just “Column” will suffice.
7. Knit!
You can create a flexdashboard template in RStudio by choosing File > New File > RMarkdown, then From Template > Flexdashboard and OK. If you have at least one chart and the appropriate output in the header, all you have to do is Knit and you’ll have a dashboard!
8. Our data
For this course, we’ll be using a publicly available dataset from a bike share service in the San Francisco area. It has records for all bike trips taken from station to station with locations and times. You’ll see this data appear in many of the exercises.
9. Let's practice!
Time to put this into practice.