Skip to contents

This document details the routines in the ewing package for adjusting daily high/low temperatures and life stage transition splines, as well as the refactoring details for tempApp() and its Shinylive WebAssembly demo.


1. Core Spline & Temperature Routines

Interactive spline adjustment functions in ewing:

Temperature-Time Spline Adjustment

General & Mean-Value Spline Adjustment

Shiny Applications & WebAssembly Demos

  • fivePlotApp() & fiveShowApp(): Modern reactive Shiny apps for parameter sensitivity and target search.
  • tempApp(): Interactive daily temperature spline and degree-day design explorer.

2. Refactoring Rationale for tempApp

Legacy Graphics Locator vs. Reactive Shiny UI

Dual Spline (High & Low Temperature) Management

  • In ewing, daily thermal fluctuation is specified by daily high and low cubic splines (High and Low elements of community$temp).
  • tempApp() allows users to switch between editing High and Low temperature splines via radio buttons, maintaining separate node coordinate vectors.

Degree-Day Integration (activeTemp())

  • Stage transition kinetics in the simulation depend on degree-days (DD). Any adjustment to high/low daily temperatures triggers activeTemp(community), which integrates degree-days using temp.repeat() and temp.spline().
  • tempApp() displays side-by-side plots:
    • Left (plot_temp): Interactive daily high (red) and low (blue) temperature splines with click-to-move node editing.
    • Right (plot_degreeday): Real-time degree-day accumulation curve generated by temp.plot(community).

Monotonicity Boundaries

  • Day knots (XX) must remain strictly increasing (x1<x2<<xnx_1 < x_2 < \dots < x_n) to allow valid cubic spline interpolation. Node moves on click are automatically constrained between neighboring knot boundaries (xi1+0.01xixi+10.01x_{i-1} + 0.01 \le x_i \le x_{i+1} - 0.01).

3. Implementation Summary

Package Function (R/tempApp.R)

  • Signature: tempApp(community = NULL, title = "Daily Temperature Design Explorer")
  • Default Input: If community is NULL, automatically initializes mysim <- ewing::init.simulation(messages = FALSE).
  • UI: bslib::page_sidebar layout featuring curve radio buttons, coordinate text inputs (x_coords, y_coords), minimum temperature input (min_temp), and side-by-side plots for temperature splines and degree-day accumulation.
  • Server: Manages reactive state, bidirectional synchronization between plot clicks and sidebar inputs, monotonicity enforcement, and real-time activeTemp() degree-day recalculations.

Shinylive WebAssembly Demo (demos/tempApp.qmd)

  • Quarto HTML document embedding {shinylive-r} code blocks (standalone: true, viewerHeight: 750).
  • Embeds lightweight standalone temperature helper functions so the app runs self-contained in browser WebAssembly without requiring a server backend.

4. Verification

  1. R Documentation & Package Export: Executed devtools::document() and devtools::load_all('.'). Verified man/tempApp.Rd creation and NAMESPACE export.
  2. Simulation Initialization Test: Verified default initialization with mysim <- init.simulation() and temperature spline extraction (getTemp(mysim, "High") & getTemp(mysim, "Low")).
  3. Degree-Day Recalculation Test: Verified that calling activeTemp() updates DegreeDay and Hour splines without error and temp.plot() renders cleanly.