misc_parameter: Miscellaneous parameter

View source: R/parameters.R

misc_parameterR Documentation

Miscellaneous parameter

Description

Create a parameter that consists of a miscellaneous object.

Usage

misc_parameter(name, value, validator, widget)

Arguments

name

character name of parameter.

value

object.

validator

function to validate changes to the parameter. This function must have a single argument and return either TRUE or FALSE depending on if the argument is valid candidate for the parameter.

widget

function to render a shiny widget. This function should must have a single argument that accepts a valid object and return a shiny.tag or shiny.tag.list object.

Value

MiscParameter object.

Examples

# load data
data(iris, mtcars)

# create table parameter can that can be updated to any other object
p1 <- misc_parameter("tbl", iris,
                     function(x) TRUE,
                     function(id, x) structure(id, .Class = "shiny.tag"))
print(p1) # print it
p1$get() # get value
p1$id # get id
p1$validate(mtcars) # check if parameter can be updated
p1$set(mtcars) # set parameter to mtcars
p1$print() # print it again

# create table parameter with validation function that requires
# all values in the first column to be less then 200 and that the
# parameter have the same column names as the iris data set
p2 <- misc_parameter("tbl2", iris,
                     function(x) all(names(x) %in% names(iris)) &&
                                 all(x[[1]] < 200),
                     function(id, x) structure(id, .Class = "shiny.tag"))
print(p2) # print it
p2$get() # get value
p2$id # get id
p2$validate(mtcars) # check if parameter can be updated
iris2 <- iris; iris2[1,1] <- 300 # create updated iris data set
p2$validate(iris2) # check if parameter can be updated
iris3 <- iris; iris2[1,1] <- 100 # create updated iris data set
p2$set(iris3) # set parameter to iris3
p2$print() # print it again


oppr documentation built on Sept. 8, 2022, 5:07 p.m.