This document outlines the architecture and data flow of the Shiny Performance Tracking system. The project processes and visualizes rodent training data collected via BControl or Bpod experimental setups.
- Raw Input:
.matfiles from behavioral rigs. - Conversion: Transformed to
.rdsfiles usingR.matlab. - Parsing: Extracted into structured R lists representing metadata and trial data.
- Aggregation: Session-level summaries are appended into
TRAINING.csv. - Visualization: Interactive Shiny app for viewing trends across animals, stages, and protocols.
.matfiles are collected in/ceph/_raw_data/_rat_training_172/SoloData/Data- A scheduled job (via
systemdon our VM) triggersExtractSaveData.R, which orchestrates the entire pipeline:- Scans the drive for new
.matfiles - Converts them to
.rdsfiles usingConvertToRDS.R - Passes the
.rdstoReadData.R, which wraps:ReadBcontrolData.R(for BControl files), orReadBpodData.R(for Bpod files)
- Receives a structured
TRAININGlist and appends it toTRAINING.csvusingTRAININGtoCSV.R
- Scans the drive for new
- The Shiny app (
shiny_app/app.R) loadsTRAINING.csvusingload_data.R - Interactive plots are generated using modules in
shiny_app/functions/
sequenceDiagram
participant Cron as Scheduler
participant Extract as ExtractSaveData.R
participant Drive as Data Drive (/ceph/_raw_data)
participant Convert as ConvertToRDS.R
participant ReadData as ReadData.R
participant Parser as Data Parser
participant CSV as TRAININGtoCSV.R
participant App as Shiny App
Note over Cron,App: Scheduled Pipeline
Cron->>Extract: systemd trigger
Extract->>Drive: scan for .mat files
Extract->>Convert: convert to .rds
Convert-->>Extract: .rds file
Note over Cron,App: Data Processing
Extract->>ReadData: pass .rds file
ReadData->>Parser: parse data
alt Data Source
Parser->>Parser: ReadBcontrolData.R
Parser->>Parser: ReadBpodData.R
end
Parser-->>ReadData: TRAINING list
ReadData-->>Extract: structured data
Extract->>CSV: append to TRAINING.csv
CSV->>App: load_data.R
Note over Cron,App: Components
Cron->>Cron: systemd service
Extract->>Extract: parallel processing
Parser->>Parser: metadata extraction
CSV->>CSV: data aggregation
sequenceDiagram
participant UI as UI Layer
participant Server as Server Logic
participant Data as Data Layer
participant Plots as Visualization
Note over UI,Plots: App Structure
UI->>Server: Dashboard Layout (app.R)
Server->>Data: load_data.R
Data-->>Server: TRAINING tibble
Note over UI,Plots: Reactive Flow
UI->>Server: Filter Changes (protocol/date/stage)
Server->>Data: Filter Data (dplyr)
Data-->>Server: Filtered Data
Server->>Plots: Generate Plots (ggplot2)
Plots-->>UI: Update Display
Note over UI,Plots: Components
UI->>UI: Sidebar Filters (selectInput/dateRangeInput)
UI->>UI: Plot Panels (plotOutput)
Server->>Server: Reactive Values (reactive/reactiveVal)
Plots->>Plots: Plot Modules (ChoiceDirectionPlot, CorrectRatioPlot)
shiny-performance-tracking/
├── shiny_app/
│ ├── app.R # Main Shiny app
│ ├── functions/ # Plot modules
│ └── TRAINING.csv # Aggregated session-level data
├── utility_functions/
│ ├── ConvertToRDS.R
│ ├── ReadBcontrolData.R
│ ├── ReadBpodData.R
│ ├── ReadData.R
│ └── TRAININGtoCSV.R
├── ExtractSaveData.R # Main batch processor
These are modular ggplot-based scripts that power the Shiny dashboard:
ChoiceDirectionPlot.R: Boxplot of pokes per directionCorrectRatioPlot.R: Line plot of correct/total trialsCompletedTrialsPlot.R: Daily trial countsStageTrackingPlot.R: Tracks stage progression per animal
Each one uses a consistent API: filters by protocol, date, stage, experimenter, and animal.
- The pipeline is idempotent: new files are processed only once.
ExtractSaveData.Ruses parallel processing for speed.- Trial-level data extraction is supported but optional (commented).
- Shiny app uses preprocessed
.csvrather than raw.rdsfor performance.