chains package logo, the word chains constructed from chain linksComplex reactive values for Shiny

What’s the problem?

{gsm.app} creates shiny apps for exploring clinical trial data

{gsm.app} inputs cascade

Groups & Participants can be temporarily invalid

Changing {gsm.app} inputs can trigger bad loads

  • 🔃 Data loads based on inputs
  • 🐢 Can be very slow
  • ⚠️ Loading with invalid inputs can error

You can’t safely set cascade order

Advice: “Set priority to infinity”

shiny::observe(
  ...,
  priority = Inf
)

How does {chains} solve this problem?

validated_reactive_val() creates self-validating reactives

my_vrv <- chains::validated_reactive_val(
  {validation_expr},
  value = {starting_value},
  default = {value_if_invalid},
  ...
)
  • Args include a shiny::reactive() for validation
  • Call it like a shiny::reactiveVal()
    • my_vrv("new_value") to set a value
    • my_vrv() always returns a valid value

vrv_fct_scalar() specifically solves the cascading input problem

chains::vrv_fct_scalar(
  {allowed_levels},
  value = {initial_value},
  default = {value_if_invalid},
  ...
)

Other vrv helpers:

  • vrv_chr() / vrv_chr_scalar()
  • vrv_dbl() / vrv_dbl_scalar()
  • vrv_int() / vrv_int_scalar()
  • vrv_lgl() / vrv_lgl_scalar()

When will this be on CRAN?

{chains} depends on {stbl}

“Be conservative in what you send. Be liberal in what you accept from others.”
Postel’s Law

I haven’t really used {chains}!

  • Refactoring {gsm.app} with {chains} will require a lot of deletion
  • Need {chains} on CRAN before I can officially do that
  • Hope to try it out on a branch ~soon

You can help!

If you have a project that could use {chains}, try it out!

# install.packages("pak")
pak::pak("shinyworks/chains")

Tell me about your experience at github.com/shinyworks/chains