This lesson is called Dashboards, part of the R in 3 Months (Fall 2022) course. This lesson is called Dashboards, part of the R in 3 Months (Fall 2022) course.
Click on the transcript to go to that point in the video. Please note that transcripts are auto generated and may contain minor inaccuracies.
Your Turn
Solution
---title:"Report on Diversity in Oregon Schools"author:"David Keyes"date:"4/28/2020"params:race_ethnicity_category:"Hispanic/Latino"output: flexdashboard::flex_dashboard:vertical_layout:scrollorientation:rows---```{rsetup, include=FALSE}knitr::opts_chunk$set(echo=FALSE,message=FALSE,warning=FALSE,cache=TRUE)``````{r}library(tidyverse)library(scales)library(ggtext)library(extrafont)library(ggalt)library(janitor)library(gt)loadfonts()```Row {data-height=300}-------------------------------------Row {data-height=300}-------------------------------------# IntroductionThisisareportforthe [OregonDepartmentofEducation](https://www.oregon.gov/ode/pages/default.aspx) ondiversityinOregonschooldistricts. HereisthemissionstatementforODE:>TheOregonDepartmentofEducationfostersequityandexcellenceforeverylearnerthroughcollaborationwitheducators, partners, andcommunities.^[Source: [ODEWebsite](https://www.oregon.gov/ode/about-us/Pages/default.aspx)]Row {data-height=500}-------------------------------------Thetablebelowshowsthedistrictswiththehighestgrowthoftheir`r params$race_ethnicity_category`studentpopulationfrom2017-2018to2018-2019. ```{r}enrollment_by_race_ethnicity<-read_rds("data/enrollment-by-race-ethnicity.rds")``````{r}options(scipen=999)enrollment_by_race_ethnicity%>%filter(race_ethnicity==params$race_ethnicity_category) %>%pivot_wider(id_cols=c(district, district_id),names_from=year,values_from=percent_of_total_at_school) %>%mutate(growth=`2018-2019`-`2017-2018`) %>%arrange(desc(growth)) %>%select(-district_id) %>%slice_max(growth, n=10) %>%gt() %>%cols_label(district="District",growth="Growth" ) %>%fmt_percent(columns=vars(`2017-2018`, `2018-2019`, growth),decimals=1 )```Row {data-height=500}-------------------------------------```{r}highlight_district<-enrollment_by_race_ethnicity%>%filter(race_ethnicity=="Hispanic/Latino") %>%filter(district=="Douglas ESD") %>%mutate(percent_display=percent(percent_of_total_at_school, accuracy=1)) %>%mutate(percent_display=case_when(year=="2018-2019"~str_glue("{percent_display} Latino students"),TRUE~percent_display ))``````{rfig.cap="Test Caption", fig.width=10}theme_student<-function() {theme_minimal(base_family="Courier New") +theme(axis.title=element_blank(),panel.grid.minor.y=element_blank(),plot.title=element_markdown(face="bold"))}enrollment_by_race_ethnicity%>%filter(race_ethnicity=="Hispanic/Latino") %>%ggplot(aes(x=year,y=percent_of_total_at_school,group=district)) +geom_line(color="lightgray",alpha=0.5) +geom_line(data=highlight_district,inherit.aes=TRUE,color="blue") +geom_text(data=highlight_district,inherit.aes=TRUE,aes(label=percent_display),hjust=c(1, 0),family="Courier New",color="blue") +scale_y_continuous(labels=percent_format(),limits=c(0, 1)) +labs(title="<span style = 'color: blue'>Douglas ESD</span> saw a large growth in its Latino student population from 2017-2018 to 2018-2019") +annotate("text",x=2.02,y=.825,hjust=0,color="gray",family="Courier New",label="Woodburn has the highest\npercentage of Latino students\nof any district") +scale_x_discrete(expand=expansion(add=c(0.1, 0.5))) +theme_student()```Row {data-height=500}-------------------------------------```{r}enrollment_by_race_ethnicity%>%filter(race_ethnicity=="Hispanic/Latino") %>%select(-c(race_ethnicity, number_of_students, district_id)) %>%pivot_wider(id_cols=district,names_from=year,values_from=percent_of_total_at_school) %>%clean_names() %>%slice(1:10) %>%ggplot(aes(x=x2017_2018,xend=x2018_2019,y=district,yend=district)) +geom_dumbbell(colour_x="gray",colour="gray",colour_xend="blue",size_x=3,size_xend=1.5) +theme_student() +scale_x_continuous(label=percent_format())```
Convert your report to a dashboard using flexdashboard
Learn More
Check out the flexdashboardwebsite to learn more about how to make flexdashboard. The layouts page is really helpful to see the ways to make various types of layouts using flexdashboard. And the examples page provides some great, um, examples!
There are other ways to make dashboards using R. You can, for example, use the distill package to make a multipage website, which resembles a dashboard. One example you saw during the Making Your Reports Shine: HTML Edition lesson included a dashboard I made using distill (for privacy reasons, I’m only showing the top of it, but there were a bunch of graphs and maps below).
Have any questions? Put them below and we will help you out!
You need to be signed-in to comment on this post. Login.
Error in yaml::yaml.load(..., eval.expr = TRUE) :
Scanner error: mapping values are not allowed in this context at line 10, column 20
Calls: ... parse_yaml_front_matter -> yaml_load ->
Execution halted
Line 10 column 20 corresponds to the x character in "flex_dashboard"
I searched online and it seems to be something to do with an extra space or indentation in the wrong place, but I can't seem to find what it is (maybe I just don't see it!)
When deciding to make dashboards, is there a criteria for doing this via Shiny vs Flexdashboard? (i.e When would it make sense to make your dashboard in Rmarkdown vs in Shiny?)
You need to be signed-in to comment on this post. Login.
Lucilla Piccari • May 31, 2021
Hello!
With the following YAML:
title: "Diversity in Oregon School Districts" author: "Lucilla Piccari" date: "07/05/2021" params: district: "Portland SD 1J" race_ethnicity: "Asian" year: "2018-2019" output: flexdashboard::flex_dashboard vertical_layout: scroll orientation: rows
I get this error message while trying to knit:
Error in yaml::yaml.load(..., eval.expr = TRUE) : Scanner error: mapping values are not allowed in this context at line 10, column 20 Calls: ... parse_yaml_front_matter -> yaml_load -> Execution halted
Line 10 column 20 corresponds to the x character in "flex_dashboard" I searched online and it seems to be something to do with an extra space or indentation in the wrong place, but I can't seem to find what it is (maybe I just don't see it!)
Thanks!
Oluwaseun Oyewole • April 28, 2022
When deciding to make dashboards, is there a criteria for doing this via Shiny vs Flexdashboard? (i.e When would it make sense to make your dashboard in Rmarkdown vs in Shiny?)