install.packages(c("flexdashboard", "DT", "shiny"))
Building dashboards with flexdashboard
flexdashboard
Pre-lecture activities
In advance of class, please install three additional packages:
flexdashboard
- this provides tools for easily building dashboardsDT
- this provides built-in data display functionalityshiny
- this provides functionality to create interactive dashboard elements
You can do this by calling
In addition, please read through
- Information about creating dashboards: https://pkgs.rstudio.com/flexdashboard
- Examples of
flexdashboard
dashboards: https://pkgs.rstudio.com/flexdashboard/articles/examples
Lecture
Acknowledgements
Material for this lecture was borrowed and adopted from
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:
- Sign up for a free account on http://www.shinyapps.io/
- Within RStudio, install the rsconnect package:
install.packages("rsconnect")
- 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.
- 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!
- 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:
- Deployed dashboard: https://stephaniehicks.shinyapps.io/OldFaithfulGeyser
- GitHub repository: https://github.com/jhu-statprogramming-fall-2024/project4-stephanieteam
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
Here are a list of resources on Shiny (more involved than Flex Dashboard):
- Main page: http://shiny.rstudio.com
- Awesome tutorial: http://shiny.rstudio.com/tutorial/
Additional practice
Here are some additional practice questions to help you think about the material discussed.
- Starting with the
GeyserFlexDashboard.Rmd
file, modify the file to also create a data display related to thewaiting
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. - 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 theeruptions
variable. Make sure to update the main plot label to indicate the selected variable. - Similar modifications can be made to the
MPGFlexDashboard.Rmd
example. Create an interface that allows the user to select two different variables from thempg
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.