This Shiny app was developed by the Sweet Corn and Potato Breeding and Genomics Lab at the University of Florida to facilitate the practical implementation of near-infrared spectroscopy (NIRS) for trait prediction. The objective of this tool is to enable users to build, validate, and deploy predictive models without requiring programming expertise.
A hosted version of the app is available online for exploration. However, we strongly recommend running the app locally for large data sets, as the web version may have session limits and slower performance, specially for the random forest model.
Access the app at: https://resendelab.shinyapps.io/NIRSpredict/
Step 1 --- Download the app files
Download or clone this repository to your computer.
Step 2 --- Install required packages
Open RStudio, then run the following in the console:
install.packages(c("shiny", "shinydashboard", "DT", "markdown",
"dplyr", "tidyr", "pls", "caret", "ranger",
"doParallel", "prospectr", "ggplot2"))This only needs to be done once.
Step 3 --- Launch the app
In RStudio, open any of the app files (ui.R, server.R, or global.R) and click the Run App button, or run:
shiny::runApp("path/to/app/folder")Replace "path/to/app/folder" with the actual path to the folder you downloaded in Step 1.
Upload Data → Preprocess Spectra → Validate Your Model → Predict New Samples
Upload a CSV file containing both NIR spectra and measured trait values. This dataset is your calibration set, it will be used to build and evaluate models throughout the app. All subsequent tabs use the data uploaded here.
Before building any model, select your wavelength range and preprocessing methods. The left panel previews all available methods on your data so you can compare them visually. Select your final method on the right panel, you can combine up to two methods.
Both PLS Regression and Random Forest are available. Which tab you use depends on what data you have available.
Do you have an independent test file?
├── Yes → External Validation
└── No
├── Do you have a train/test column? → Custom Train/Test Split
└── No → K-fold Cross-Validation
Once you are satisfied with model performance from the validation step and want to predict new samples, go to Tab 6 to generate predictions that have no measured trait values, only NIR spectra.
Upload your calibration dataset containing both NIR spectra and measured trait values. The platform accepts CSV files. Spectral columns must be named as wavelength numbers, in one of two formats:
| Format | Example |
|---|---|
| Plain number | 900, 901, 1000 |
| X + number | X900, X901, X1000 |
Avoid starting any non-spectral column name with X, as all X-prefixed columns are interpreted as spectral data.
Single-file format (trait + spectra combined):
| SampleID | Trait | 900 | 901 | ... | 1700 |
|---|---|---|---|---|---|
| S1 | 12.3 | 0.45 | 0.46 | ... | 0.89 |
Two-file format: upload a trait file and a spectra file separately; they will be joined automatically by matching columns.
| Options: |
| Trait column: the measured response variable to be predicted. |
| Sample ID column (optional): if multiple rows share the same sample ID (i.e., spectral replicates), they will be averaged before modeling, both spectra and trait values. |
Threshold filter (optional): filter samples based on a numeric column before modeling (e.g., remove outliers, select a quality subgroup). You can choose the column, operator (<, <=, ==, >=, >), and threshold value. |
No data yet? A sample dataset (Seed_lot.csv) is included with the app and can be loaded directly from the Upload Data tab. This dataset comes from [citation], where NIRSpredict was applied to predict sweet corn seed lot quality from single-kernel near-infrared spectra. Use it to explore the platform before working with your own data.
NIR spectra often contain physical measurement artifacts, scatter effects, baseline shifts, and instrument noise, that are unrelated to sample composition. Preprocessing removes or reduces these artifacts before modeling.
Wavelength range selection: restrict the analysis to a specific spectral window. Only wavelengths within the selected range will be used in modeling.
Available methods:
| Method | Abbreviation | What it does |
|---|---|---|
| Mean Centering | MC | Subtracts the mean spectrum from all spectra |
| Standard Normal Variate | SNV | Centers and scales each spectrum individually by its own mean and standard deviation; corrects for light scatter and particle size effects |
| Multiplicative Scatter Correction | MSC | Aligns each spectrum to the mean of the calibration set, corrects for both multiplicative and additive scatter effects using linear regression against the reference |
| Savitzky-Golay Smoothing | Smoothing | Fits a polynomial to a moving window of data points to reduce noise while preserving the spectral shape |
| Derivatives | Computed using Savitzky-Golay filter. Reduces noise and correct baseline shifts. |
Two-step preprocessing: you can combine two methods sequentially (e.g., MSC → Second Derivative, SNV → Smoothing).
Note on Savitzky-Golay parameters:
- Window size must be an odd integer (e.g., 5, 7, 11).
- Polynomial order must be less than the window size.
Use this tab when all your data comes from a single dataset and you have no independent samples set for testing. K-fold cross-validation gives an estimate of model performance. The dataset is split into k folds. Each fold serves as the test set exactly once, with the remaining folds used for training. This process is repeated n times with different random partitions. Results are reported as mean ± standard deviation across repetitions.
PLS component selection is performed by internal cross-validation on the training folds only. The test fold is never used for parameter tuning.The internal validation strategy adapts automatically to the size of each training fold. For PLS, the number of segments used to select the optimal number of components scales with sample size, roughly one segment per five samples, up to a maximum of 10. For RF, the number of folds used to tune the model follows a similar logic with n < 30, 5 when n < 100, and 10 otherwise
PLS component selection methods:
| Method | Description |
|---|---|
| Minimize RMSEP | Chooses the number of components that minimizes the root mean squared error of prediction across the internal CV folds |
| One-sigma heuristic | Selects the simplest model (fewest components) whose RMSEP falls within one standard error of the minimum |
| Permutation test | Uses randomization to identify the number of components that explain significantly more variance than chance |
Random Forest tuning: RF models are tuned via internal cross-validation using ranger with permutation-based variable importance. The number of variables tried at each split (mtry) is optimized automatically.
Use this tab when your dataset already contains a column that designates certain samples as a test set, for example, a column with values like train/test, or ENV1/ENV2. You select the column containing the split labels and specify the value that identifies the test set. The app will use all other samples for training..
PLS component selector: after training, a slider lets you evaluate test set performance across different numbers of components without retraining.
Use this tab when you have an independent dataset, collected from different samples, a different location, or a different season, to assess how well your model generalizes beyond the calibration data.
The calibration model is trained on the full uploaded dataset. The external test file is then preprocessed using exactly the same settings selected in Tab 2 (same wavelength range, same methods, same parameters), and predictions are generated.
Upload requirements for the test file: same CSV format as the calibration data, must contain the trait column with the same column name, must cover the same wavelength range as the calibration data.
Use this tab when you have new NIR spectra with no measured trait values and want to generate predictions. This is the deployment step, after validating your model in one of the previous tabs, you train a final calibration model on your full dataset and apply it to new samples.
Click the Save session button in the sidebar to generate a URL that captures your current settings: preprocessing method, wavelength range, model parameters, and validation choice. Save or share this URL to reproduce an exact analysis configuration.
# Interface
shiny
shinydashboard
DT
markdown
# Data manipulation
dplyr
tidyr
# Modeling
pls # PLS regression
caret # RF training framework and cross-validation
ranger # Fast Random Forest implementation
doParallel # Parallel processing for RF
# Spectral preprocessing
prospectr # SNV, MSC, Savitzky-Golay
# Visualization
ggplot2Install all at once:
install.packages(c("shiny", "shinydashboard", "DT", "markdown",
"dplyr", "tidyr", "pls", "caret", "ranger",
"doParallel", "prospectr", "ggplot2"))If you use this platform in your research, please cite:
[Citation to be added]
This tool is under active development. For questions, suggestions, or bug reports, please contact:
- Rafaela Graciano --- rafaela.pgraciano@gmail.com{.email}
- Noriko Suzuki --- nsuzuki@ufl.edu{.email}
- Sweet Corn and Potato Breeding and Genomics Lab, University of Florida
This project is licensed under the MIT License. © 2026 Sweet Corn and Potato Breeding and Genomics Lab, University of Florida.