define_input: Define 'RAVE' module inputs

Description Usage Arguments Format Details Examples

Description

Used in 'RAVE' module file 'comp.R' to define input components

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
define_input(
  definition,
  init_args,
  init_expr,
  keyword = "inputId",
  update_level = 2,
  ...
)

UPDATE_LEVEL

Arguments

definition

R expression; see example or details

init_args

arguments to change when data is loaded

init_expr

expression to calculate argument values

keyword

argument refering to shiny input ID, default is "inputId"

update_level

update level: 1, 2, or 0; see details.

...

passed to other methods

Format

An object of class list of length 3.

Details

definition is un-evaluated R expression defining shiny inputs for example textInput('text_id', 'Input:'). All inputs in the following packages are supported: 'shiny' , 'dipsaus', 'ravecore', 'raveio'

Because when defining inputs, there is no assumption on data content, all inputs values/choices should not be hard-coded. For example, before any subject is loaded, condition types are unknown, hence an input selecting condition types will need 'choices' to be reloaded once subject is loaded. init_args specify which arguments need to be changed once data is loaded. init_expr will be evaluated after initialization code and variables created during this procedure will be used to update input arguments.

update_level has three levels: 1 is render only, updating input only results in outputs to be re-rendered; 2 is run all, not only outputs will be re-rendered, main function will be executed; 0 is manual input, meaning the input will remain as ordinary shiny input and one has to use shiny observer to capture value changes

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
## Not run: 

# This code is ran in rave_validate
repo <- loaded_rave_repository(
  'demo/DemoSubject' ,
  reference = 'default',
  epoch = 'auditory_onset',
  before_onset = 1,
  after_onset = 2
)

define_input(

  # No condition is known before data/subject is chosen
  # repo is not available at this time
  definition = shiny::selectInput(inputId = 'cond', label = 'Condition',
                                  choices = character(0), selected = NULL),

  # two arguments will be changed once subject is loaded
  init_args = c('choices', 'selected'),

  init_expr = {
    # at this moment, you know some information about subject
    # for example, repo is created and is available
    choices <- unique(repo$epoch$table$Condition)
    # So does selected
    selected <- raveio::get_val2(repo, 'cond', choices[[1]])
  }

)

## End(Not run)

dipterix/ravecore documentation built on Aug. 5, 2020, 2:14 p.m.