@winm2m/react-stats-ui
v0.7.0
Published
React UI component for inferential statistics workflows in the browser
Maintainers
Readme
@winm2m/react-stats-ui
React UI component for browser-based inferential statistics workflows, powered by @winm2m/inferential-stats-js.
Installation
npm install @winm2m/react-stats-ui @winm2m/inferential-stats-jsPeer dependencies:
react^18.2.0 || ^19.0.0react-dom^18.2.0 || ^19.0.0
What the component provides
- Dataset management with IndexedDB (import XLSX, select/delete dataset, drag-drop upload zone).
- Analysis selection popover with current analysis display, grouped into 6 categories.
- Variable assignment UI with drag/drop, double-click assignment, and role-aware validation.
- 16 built-in analysis types (t-test, ANOVA, regression, clustering, factor/component methods, etc.).
- Auto-run queue execution when inputs change (analysis, role assignment, dataset, options).
- Worker lifecycle UX (signal indicator, loading state, error state, initial blocking overlay).
- Result area with APA table rendering, JSON toggle, payload toggle, and formatted clipboard copy.
- Imperative external control API via React ref (runtime data injection, result panel visibility, APA clipboard copy, direct analysis calls).
- Two layout modes:
full: split control/result with resizable vertical dividerminimal: compact flow with slide-up result panel
Supported analyses
- Frequencies
- Descriptives
- Crosstabs
- Independent-Samples T-Test
- Paired-Samples T-Test
- One-Way ANOVA
- Post-hoc Tukey HSD
- Linear Regression (OLS)
- Binary Logistic Regression
- Multinomial Logistic Regression
- K-Means Clustering
- Hierarchical Clustering
- Exploratory Factor Analysis
- Principal Component Analysis
- Multidimensional Scaling
- Cronbach Alpha
Basic usage
import * as React from "react";
import { StatsWorkbench } from "@winm2m/react-stats-ui";
export function App() {
return (
<div style={{ width: "100vw", height: "100vh" }}>
<StatsWorkbench />
</div>
);
}Component API
StatsWorkbench props:
className?: stringstyle?: React.CSSPropertiesinitialAnalysis?: AnalysisKind(default:"frequencies")layoutMode?: "full" | "minimal"(default:"full")language?: "en" | "ar" | "zh" | "fr" | "ru" | "es" | "ko" | "ja" | "vi"(default:"en")showDatasetPopover?: boolean(default:true)minimalAutoShowResultEnabled?: boolean(default:true)- When
falsein minimal layout, auto-show is disabled and theAuto show resultswitch is hidden.
- When
analysisExecutor?: (payload: AnalysisPayload) => Promise<unknown>onResult?: (result: AnalysisResult) => void
StatsWorkbench ref (StatsWorkbenchControl):
injectData({ rows, columns?, id?, name? })- Injects runtime analysis data without writing to IndexedDB.
- If
columnsis omitted, variable metadata is inferred fromrows.
clearInjectedData()executeAnalysis(method, inputWithoutData?)runFrequencies(inputWithoutData?)runDescriptives(inputWithoutData?)runCrosstabs(inputWithoutData?)runTtestIndependent(inputWithoutData?)runTtestPaired(inputWithoutData?)runAnovaOneway(inputWithoutData?)runPosthocTukey(inputWithoutData?)runLinearRegression(inputWithoutData?)runLogisticBinary(inputWithoutData?)runLogisticMultinomial(inputWithoutData?)runKmeans(inputWithoutData?)runHierarchicalCluster(inputWithoutData?)runEfa(inputWithoutData?)runPca(inputWithoutData?)runMds(inputWithoutData?)runCronbachAlpha(inputWithoutData?)- All 16 async wrappers call
@winm2m/inferential-stats-jsand always inject previously provided runtime data asdata.
- All 16 async wrappers call
setResultVisible(next)(minimal layout)toggleResultVisible()(minimal layout)setAutoShowResult(next)toggleAutoShowResult()getAutoShowResult()copyApaTable()
Example:
import * as React from "react";
import { StatsWorkbench, type StatsWorkbenchControl } from "@winm2m/react-stats-ui";
export function App() {
const workbenchRef = React.useRef<StatsWorkbenchControl>(null);
const runExternal = async () => {
workbenchRef.current?.injectData({
name: "runtime-dataset",
rows: [
{ score: 10, group: "A" },
{ score: 12, group: "A" },
{ score: 14, group: "B" },
{ score: 15, group: "B" }
]
});
await workbenchRef.current?.runTtestIndependent({
variable: "score",
groupVariable: "group",
group1Value: "A",
group2Value: "B",
equalVariance: true
});
await workbenchRef.current?.copyApaTable();
};
return (
<>
<button onClick={() => void runExternal()}>Run external t-test</button>
<div style={{ width: "100vw", height: "90vh" }}>
<StatsWorkbench ref={workbenchRef} layoutMode="minimal" />
</div>
</>
);
}Internationalization
The workbench includes built-in i18n via i18next + react-i18next.
Supported languages:
en(English)ar(Arabic)zh(Chinese)fr(French)ru(Russian)es(Spanish)ko(Korean)ja(Japanese)vi(Vietnamese)
Coverage includes core UI labels, placeholders, role prompts, options labels, run-state messages, and result-view helper text.
Use language prop to set the active language:
<StatsWorkbench language="ko" />Exports:
StatsWorkbenchAnalysisKindStatsWorkbenchPropsAnalysisPayloadAnalysisResultExternalDataInputStatsWorkbenchControl
Execution behavior
- The workbench builds a payload and runs analysis when configuration is valid.
- Input changes are queued and processed sequentially.
- While running, duplicate execution is blocked.
- In
minimalmode, result view is a slide-up panel. - In
minimalmode, result panel can be shown/hidden by UI toggle or external control. - In
minimalmode, multi-item role updates (for multi roles likevariables/independentVariables) use a manual Play trigger shown in Role Assignment when execution is valid.
Result behavior
- APA table view is default.
- More menu contains:
- APA Table <-> JSON toggle
- Show/Hide API payload
- Copy button copies APA tables in both plain text and HTML format for paste into Excel/Word (formatted headers/borders).
Demo page
docs/demo.html demonstrates CDN usage and local dev build usage:
Live demo: https://winm2m.github.io/react-stats-ui/demo.html
?dev=trueloads/dist/index.jsotherwise loads published package from npm via ESM CDN
includes demo selectors for:
- Theme:
light/dark - Layout:
full/minimal
- Theme:
Storybook
Scripts:
npm run storybook
npm run build-storybook
npm run test
npm run test:ciCI runs typecheck, test:ci, and build automatically on push/PR via .github/workflows/ci.yml.
Story file: src/stats-workbench.stories.tsx
Interactive controls include:
Section Layout:full/minimalLanguage:en/ar/zh/fr/ru/es/ko/ja/viTheme:light/dark/customBackgroundBackground TransparentTextBorderMajorMinorWarningErrorInfoRounded Edges
Theme behavior:
- Selecting
lightordarkapplies a preset palette. - Editing any themed color while
light/darkis active switches mode tocustom.
Notes
- Internal UI uses Radix primitives and
lucide-reacticons. - Worker URL can be controlled via
window.__WINM2M_INFERENTIAL_WORKER_URL__. - The component is designed to fill the parent container.
Project metadata
- Contribution guide:
CONTRIBUTING.md - Citation metadata:
CITATION.cff
