Tutorial Dashboard
  • Welcome
  • Charts
  • Timeline
  • Text & Content
  • Showcase Dashboard

Welcome

View Full Dashboard Code
library(dashboardr)
library(gssr)

# === DATA PREPARATION ===

# Cross-sectional data (for bar/stackedbar charts)
data(gss_panel20, package = "gssr")
gss_clean <- gss_panel20 %>%
  dplyr::mutate(
    degree = as.character(haven::as_factor(degree_1a)),
    happy = as.character(haven::as_factor(happy_1a))
  ) %>%
  dplyr::filter(!is.na(degree), !is.na(happy))

# Time series data (for timeline chart)
data(gss_all, package = "gssr")
gss_time <- gss_all %>%
  dplyr::mutate(happy = as.character(haven::as_factor(happy))) %>%
  dplyr::filter(!is.na(happy), !is.na(year),
                happy %in% c("very happy", "pretty happy", "not too happy"))

# === CHARTS PAGE ===

chart_vizzes <- create_content() %>%
  add_viz(type = "bar",
          x_var = "degree",
          title = "Education Level Distribution",
          subtitle = "Count of respondents by highest degree attained",
          x_label = "Education",
          y_label = "Count",
          x_order = c("less than high school", "high school",
                      "associate/junior college", "bachelor's", "graduate"),
          color_palette = c("#3498db", "#2ecc71", "#9b59b6", "#e74c3c", "#f39c12"),
          height = 400) %>%
  add_viz(type = "stackedbar",
          x_var = "degree",
          stack_var = "happy",
          title = "Happiness by Education Level",
          subtitle = "Self-reported happiness across education groups",
          x_label = "Education",
          y_label = "Percentage",
          stack_label = "Happiness",
          stacked_type = "percent",
          x_order = c("less than high school", "high school",
                      "associate/junior college", "bachelor's", "graduate"),
          stack_order = c("very happy", "pretty happy", "not too happy"),
          color_palette = c("#27ae60", "#f39c12", "#e74c3c"),
          height = 450)

charts_page <- create_page(name = "Charts", data = gss_clean, icon = "ph:chart-bar") %>%
  add_content(chart_vizzes)

# === TIMELINE PAGE ===

timeline_viz <- create_content() %>%
  add_viz(type = "timeline",
          time_var = "year",
          y_var = "happy",
          title = "Happiness Trends Over Time (1972-2024)",
          subtitle = "How has happiness changed across 50+ years?",
          x_label = "Year",
          y_label = "Percentage",
          y_levels = c("very happy", "pretty happy", "not too happy"),
          color_palette = c("#27ae60", "#f39c12", "#e74c3c"),
          height = 450)

timeline_page <- create_page(name = "Timeline", data = gss_time, icon = "ph:chart-line") %>%
  add_content(timeline_viz)

# === TEXT & CONTENT PAGE ===

text_content <- create_content() %>%
  add_text(md_text(
    "This page demonstrates text formatting and content blocks.",
    "",
    "You can use **bold text**, *italics*, and `inline code`.",
    "",
    "Lists work too:",
    "",
    "- First item with **bold**",
    "- Second item with *italics*",
    "- Third item with `code`"
  )) %>%
  add_accordion(
    title = "What is an accordion?",
    text = "A collapsible content block. Great for FAQs or code examples."
  )

text_page <- create_page(name = "Text & Content", icon = "ph:chalkboard-simple-bold") %>%
  add_content(text_content)

# === CREATE DASHBOARD ===

dashboard <- create_dashboard(
  output_dir = "tutorial_dashboard",
  title = "Tutorial Dashboard",
  logo = "gss_logo.png",
  theme = "flatly"
) %>%
  add_pages(charts_page, timeline_page, text_page)

# Generate the dashboard
generate_dashboard(dashboard)

View complete R script on GitHub

Welcome to the Tutorial Dashboard, providing insights into the General Social Survey (GSS) data!

This dashboard demonstrates how to use the dashboardr package to create beautiful, interactive dashboards using real survey data.


Dashboard File Structure

dashboardr generates Quarto dashboards. Quarto is an open-source publishing system that renders .qmd (Quarto Markdown) files into HTML, PDF, and other formats. You write content in Markdown with embedded R code, and Quarto renders it into a polished output.

When you run tutorial_dashboard(), the following files are created:

tutorial_dashboard/
├── _quarto.yml              # Project config (title, theme, navigation)
├── index.qmd                # Landing page (this page)
├── charts.qmd               # Bar and stacked bar charts
├── timeline.qmd             # Time series chart (uses gss_all data)
├── text___content.qmd       # Text and content blocks demo
└── showcase_dashboard.qmd   # Full feature demonstration

Key files:

  • _quarto.yml - The project configuration file. Controls the dashboard title, theme, navbar, and which pages appear in the navigation.
  • .qmd files - Each page is a separate Quarto Markdown file containing text and R code chunks that generate visualizations.

To render the dashboard, Quarto executes the R code in each .qmd file and produces the final HTML. dashboardr handles all the code generation for you!


About the Data

This dashboard uses data from the General Social Survey (GSS), a nationally representative survey of adults in the United States conducted since 1972. We explore patterns in:

  • Happiness - Self-reported happiness levels (very happy, pretty happy, not too happy)
  • Education - Highest degree attained
  • Trends over time - How attitudes change across 50+ years of surveys (1972-2024)

Getting Started with dashboardr

Each visualization includes a collapsible View R Code section showing exactly how it was created.

Back to top

© 2025 dashboardr Package - All Rights Reserved

 

dashboardr logoPowered by dashboardr