Skip to content

Defining default selected values for form controls

Nathan Eastwood edited this page Aug 25, 2016 · 2 revisions

Setting up defaults for form controls

Suppose we have a dropdown list, checkbox group or multi-select list in an RCAP dashboard which gets its values from an R function in the notebook. There are currently two ways of defining default selected control values.

Option 1

We can define defaults by returning our values in a list.

# Cell 1
getVals <<- function(){
  list(value = c("potatoes", "tomatoes", "plums"),
       selected = c("plums", "tomatoes"))
}

We must always return our values as a list with the names value and selected. selected represents the defaults. In this case, the default selected values will be "plums" and "tomatoes".

Option 2

The other option is to define a default variable which has the same variable name as defined in our form control (this always defaults to variable, which is what we use here for demonstrative purposes).

# Cell 1
variable <<- c("plums", "tomatoes")

Then we define our function which returns an unnamed vector of values.

# Cell 2
getVals <<- function(){
  values <- c("potatoes", "tomatoes", "plums")
}

In this case, the default selected value will again be "plums" and "tomatoes".

Clone this wiki locally