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.

input_count
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 = "")
  1. input_count ← 4

    1input_count <- 42base <- c(5, 10, 15)
    values this step4input_count
  2. base ← 5, 10, 15

    1input_count <- 42base <- c(5, 10, 15)3limit <- input_count * 3
    values this step5, 10, 15base
  3. limit ← 12

    2base <- c(5, 10, 15)3limit <- input_count * 34filtered <- base[base <= limit]
    values this step12limit4input_count
  4. filtered ← 5, 10

    3limit <- input_count * 34filtered <- base[base <= limit]5total <- sum(filtered)
    values this step5, 10filtered5, 10, 15base12limit
  5. total ← 15

    4filtered <- base[base <= limit]5total <- sum(filtered)6label <- paste("reactive", total, sep = ":")
    values this step15total5, 10filtered
  6. label ← reactive:15

    5total <- sum(filtered)6label <- paste("reactive", total, sep = ":")7cat(label, "\n", sep = "")
    values this stepreactive:15label15total
  7. cat(label, " ", sep = "")

    6label <- paste("reactive", total, sep = ":")7cat(label, "\n", sep = "")
    outputreactive:15
    values this stepreactive:15label
  1. input_count ← 2

    1input_count <- 22base <- c(5, 10, 15)
    values this step2input_count
  2. base ← 5, 10, 15

    1input_count <- 22base <- c(5, 10, 15)3limit <- input_count * 3
    values this step5, 10, 15base
  3. limit ← 6

    2base <- c(5, 10, 15)3limit <- input_count * 34filtered <- base[base <= limit]
    values this step6limit2input_count
  4. filtered ← 5

    3limit <- input_count * 34filtered <- base[base <= limit]5total <- sum(filtered)
    values this step5filtered5, 10, 15base6limit
  5. total ← 5

    4filtered <- base[base <= limit]5total <- sum(filtered)6label <- paste("reactive", total, sep = ":")
    values this step5total5filtered
  6. label ← reactive:5

    5total <- sum(filtered)6label <- paste("reactive", total, sep = ":")7cat(label, "\n", sep = "")
    values this stepreactive:5label5total
  7. cat(label, " ", sep = "")

    6label <- paste("reactive", total, sep = ":")7cat(label, "\n", sep = "")
    outputreactive:5
    values this stepreactive:5label
  1. input_count ← 6

    1input_count <- 62base <- c(5, 10, 15)
    values this step6input_count
  2. base ← 5, 10, 15

    1input_count <- 62base <- c(5, 10, 15)3limit <- input_count * 3
    values this step5, 10, 15base
  3. limit ← 18

    2base <- c(5, 10, 15)3limit <- input_count * 34filtered <- base[base <= limit]
    values this step18limit6input_count
  4. filtered ← 5, 10, 15

    3limit <- input_count * 34filtered <- base[base <= limit]5total <- sum(filtered)
    values this step5, 10, 15filtered5, 10, 15base18limit
  5. total ← 30

    4filtered <- base[base <= limit]5total <- sum(filtered)6label <- paste("reactive", total, sep = ":")
    values this step30total5, 10, 15filtered
  6. label ← reactive:30

    5total <- sum(filtered)6label <- paste("reactive", total, sep = ":")7cat(label, "\n", sep = "")
    values this stepreactive:30label30total
  7. cat(label, " ", sep = "")

    6label <- paste("reactive", total, sep = ":")7cat(label, "\n", sep = "")
    outputreactive:30
    values 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.