A Shiny application for analyzing weighted survey data with grouping and statistical comparisons.
R/
├── app.R # Main application entry point
├── global.R # Global settings and library loading
├── ui.R # User interface definition
├── server.R # Server logic
├── functions/ # Modular function files
│ ├── utils.R # General utility functions
│ ├── data_io.R # Data reading and validation
│ ├── factors.R # Factor creation and manipulation
│ ├── ui_helpers.R # UI generation helpers
│ ├── analysis.R # Survey data analysis functions
│ ├── plotting.R # Plotting and visualization
│ ├── statistics.R # Statistical tests
│ └── grouped_analysis.R # Multi-select question analysis
├── tests/ # Unit tests
│ ├── testthat.R # Test runner
│ └── testthat/ # Individual test files
│ ├── test-utils.R
│ ├── test-factors.R
│ └── ...
└── README.md # This file
- Install required packages:
install.packages(c(
"shiny", "readxl", "dplyr", "tidyr", "stringr", "forcats",
"ggplot2", "DT", "scales", "survey", "tibble", "testthat"
))- Optional: Install RColorBrewer for enhanced color palettes:
install.packages("RColorBrewer")# From the project root directory
shiny::runApp()Or simply run app.R in RStudio.
# Run all tests
testthat::test_dir("tests/testthat")
# Or use devtools
devtools::test()- Weighted proportion plots for single questions
- Primary and optional secondary grouping variables
- Customizable Likert color palettes
- Exclude specific response levels (Don't know, Prefer not to say, etc.)
- Download plots as JPG and tables as CSV
- Analysis of multi-select questions (@ prefixed variables)
- Heatmap visualization of selection rates by group
- Significance testing with Rao-Scott chi-squared tests
- Significance markers (★) for notable differences
- Chi-squared tests for overall differences across groups
- Pairwise Wald comparisons with Bonferroni correction
- Custom grouping of response levels
- Custom grouping of demographic groups
The application expects an Excel workbook (.xlsx) with three sheets:
Contains the raw survey responses with one row per respondent.
Two columns:
Variable: Variable name (must match Data columns)Label: Human-readable label
Three columns:
Variable: Variable nameValue: Coded value (e.g., "1", "2")Label: Human-readable label for the value
Functions are organized by purpose for easy testing and maintenance:
- utils.R: General utilities (null coalescing, filename sanitization)
- data_io.R: Reading and validating Excel workbooks
- factors.R: Creating factors with value labels, collapsing levels
- ui_helpers.R: Building UI elements (dropdowns, headers)
- analysis.R: Preparing data for analysis, creating survey designs
- plotting.R: Creating plots and tables
- statistics.R: Statistical tests (chi-squared, pairwise comparisons)
- grouped_analysis.R: Multi-select question analysis and visualization
Unit tests are provided for core functions. Tests are organized by function file:
test-utils.R: Tests for utility functionstest-factors.R: Tests for factor manipulation- Add more test files as needed for comprehensive coverage
To add new tests:
- Create a test file in
tests/testthat/namedtest-[function_file].R - Follow the naming convention:
test_that("description", { ... }) - Run tests with
testthat::test_dir("tests/testthat")
- Survey designs use the
surveypackage for weighted analysis - Negative codes in numeric variables are treated as missing
- The app supports files up to 100 MB
- Lonely PSUs are adjusted automatically in survey designs