Building dashboards with flexdashboard

Introduction to building dashboards in R with flexdashboard
Author
Affiliation

Department of Biostatistics, Johns Hopkins

Published

December 3, 2024

Pre-lecture activities

Important

In advance of class, please install three additional packages:

  • flexdashboard - this provides tools for easily building dashboards
  • DT - this provides built-in data display functionality
  • shiny - this provides functionality to create interactive dashboard elements

You can do this by calling

install.packages(c("flexdashboard", "DT", "shiny"))

In addition, please read through

  1. Information about creating dashboards: https://pkgs.rstudio.com/flexdashboard
  2. Examples of flexdashboard dashboards: https://pkgs.rstudio.com/flexdashboard/articles/examples

Lecture

Acknowledgements

Material for this lecture was borrowed and adopted from

  • “R for Data Science” by Grolemund and Wickham, sections 29.6 and 29.7.2. It is based on lecture notes initially developed by Margaret Taub and Leah Jager.

Learning objectives

Learning objectives

At the end of this lesson you will:

  • Know how to create a basic dashboard to display data analysis elements using flexdashboard
  • Add interactive elements to your dashboard using tools from the shiny package
  • Have resources to assist you in developing your own more complex dashboard to clearly present data and interactive elements

Slides

Deploying a dashboard

Here are some helpful pointers for getting a free Shinyapps.io account and then publishing your dashboard to the web:

Deploying a Shiny app in RStudio
  1. Sign up for a free account on http://www.shinyapps.io/
  2. Within RStudio, install the rsconnect package: install.packages("rsconnect")
  3. Within RStudio Cloud, select “Tools” then “Global Options…” and then select “Publishing” from the left-hard menu. (Within the non-cloud RStudio, under the “Preferences” menu, click on “Publishing”.) Click the “Connect” button next to the publishing accounts box and then “Shinypps.io” to link your shinyapps.io account to your RStudio. Click on “Shinyapps.io” from the pop-up menu, and then follow the instructions to link your account. This involves copying and pasting a token from your account into the box in R Studio.
  4. Now you are ready to publish! Click the “Run Document” button to create your app; then click “Publish” in the upper right hand corner of your app (the publish icon is a blue circle with blue curves around it). Choose “Publish just this document” from the pop-up menu. Make sure the selected destination account is your shinyapps.io account. You can change the name of the app if you want. Then click publish!
  5. If you want to delete the app (unpublish it), you need to do this from within your shinyapps.io account. Go to http://www.shinyapps.io/ and log in to your account. Click on applications to manage your applications. You must first archive your app before you can delete it.

Stephanie’s dashboard

I have deployed the Old Faithful dashboard to my own Shiny account and linked the public github repo (on GitHub Classroom) to give as an example:

Class activity

For the rest of the time in class, you and your team will work on the final project. Stephanie will walk around to answer questions and to help in anyway I can.

Post-lecture

Tip

Here are a list of resources on Shiny (more involved than Flex Dashboard):

Additional practice

Here are some additional practice questions to help you think about the material discussed.

Questions
  1. Starting with the GeyserFlexDashboard.Rmd file, modify the file to also create a data display related to the waiting variable. This display could be on another tab, or you could create an entire new page. You could allow the user to specify if they want a histogram or a boxplot with a dropdown selector.
  2. Alternatively, keep the layout simple with a single pane for the plot, but allow the user to select whether they want to display a histogram of the waiting variable or the eruptions variable. Make sure to update the main plot label to indicate the selected variable.
  3. Similar modifications can be made to the MPGFlexDashboard.Rmd example. Create an interface that allows the user to select two different variables from the mpg data set and then create an appropriate data display to illustrate the relationship between these two variables, updating any plot labels to reflect the selected variables.