Shiny Concepts Without Runtime
Reactive Value
Recompute a Summary
Reactive expressions recompute derived values when their inputs change.
Program
Play the script to change the modeled input count and see the derived total update.
reactive_value.R
Replay: real traced execution (multi-file project)
input_count <- 4
base <- c(5, 10, 15)
limit <- input_count * 3
filtered <- base[base <= limit]
total <- sum(filtered)
label <- paste("reactive", total, sep = ":")
cat(label, "\n", sep = "")
input_count <- 2
base <- c(5, 10, 15)
limit <- input_count * 3
filtered <- base[base <= limit]
total <- sum(filtered)
label <- paste("reactive", total, sep = ":")
cat(label, "\n", sep = "")
input_count <- 6
base <- c(5, 10, 15)
limit <- input_count * 3
filtered <- base[base <= limit]
total <- sum(filtered)
label <- paste("reactive", total, sep = ":")
cat(label, "\n", sep = "")
input_count ← 4
1input_count <- 42base <- c(5, 10, 15)values this step4input_countbase ← 5, 10, 15
1input_count <- 42base <- c(5, 10, 15)3limit <- input_count * 3values this step5, 10, 15baselimit ← 12
2base <- c(5, 10, 15)3limit <- input_count * 34filtered <- base[base <= limit]values this step12limit4input_countfiltered ← 5, 10
3limit <- input_count * 34filtered <- base[base <= limit]5total <- sum(filtered)values this step5, 10filtered5, 10, 15base12limittotal ← 15
4filtered <- base[base <= limit]5total <- sum(filtered)6label <- paste("reactive", total, sep = ":")values this step15total5, 10filteredlabel ← reactive:15
5total <- sum(filtered)6label <- paste("reactive", total, sep = ":")7cat(label, "\n", sep = "")values this stepreactive:15label15totalcat(label, " ", sep = "")
6label <- paste("reactive", total, sep = ":")7cat(label, "\n", sep = "")outputreactive:15values this stepreactive:15label
input_count ← 2
1input_count <- 22base <- c(5, 10, 15)values this step2input_countbase ← 5, 10, 15
1input_count <- 22base <- c(5, 10, 15)3limit <- input_count * 3values this step5, 10, 15baselimit ← 6
2base <- c(5, 10, 15)3limit <- input_count * 34filtered <- base[base <= limit]values this step6limit2input_countfiltered ← 5
3limit <- input_count * 34filtered <- base[base <= limit]5total <- sum(filtered)values this step5filtered5, 10, 15base6limittotal ← 5
4filtered <- base[base <= limit]5total <- sum(filtered)6label <- paste("reactive", total, sep = ":")values this step5total5filteredlabel ← reactive:5
5total <- sum(filtered)6label <- paste("reactive", total, sep = ":")7cat(label, "\n", sep = "")values this stepreactive:5label5totalcat(label, " ", sep = "")
6label <- paste("reactive", total, sep = ":")7cat(label, "\n", sep = "")outputreactive:5values this stepreactive:5label
input_count ← 6
1input_count <- 62base <- c(5, 10, 15)values this step6input_countbase ← 5, 10, 15
1input_count <- 62base <- c(5, 10, 15)3limit <- input_count * 3values this step5, 10, 15baselimit ← 18
2base <- c(5, 10, 15)3limit <- input_count * 34filtered <- base[base <= limit]values this step18limit6input_countfiltered ← 5, 10, 15
3limit <- input_count * 34filtered <- base[base <= limit]5total <- sum(filtered)values this step5, 10, 15filtered5, 10, 15base18limittotal ← 30
4filtered <- base[base <= limit]5total <- sum(filtered)6label <- paste("reactive", total, sep = ":")values this step30total5, 10, 15filteredlabel ← reactive:30
5total <- sum(filtered)6label <- paste("reactive", total, sep = ":")7cat(label, "\n", sep = "")values this stepreactive:30label30totalcat(label, " ", sep = "")
6label <- paste("reactive", total, sep = ":")7cat(label, "\n", sep = "")outputreactive:30values this stepreactive:30label
input dependency
The derived limit depends on the selected input count.
reactive expression
Filtering and summing model a reactive expression recomputing from inputs.
output value
The final label is the value an output binding could display.