| Title: | A Framework To Manage Tabular Items |
|---|---|
| Description: | A framework to manage tabular items and a set of tools to implement it within R Shiny applications. |
| Authors: | Philippe Peret [aut, cre, cph] (ORCID: <https://orcid.org/0009-0003-9666-7490>) |
| Maintainer: | Philippe Peret <[email protected]> |
| License: | GPL (>= 3) |
| Version: | 0.8.0.9000 |
| Built: | 2026-10-01 20:28:13 UTC |
| Source: | https://github.com/thekangaroofactory/kitems |
Sort Items
adjust(items, config, item = get_context())adjust(items, config, item = get_context())
items |
a data.frame of the items. |
config |
the config list. |
item |
the name (id) of the item group. |
The sorting order is given by the sort entry in the config list.
When item is set in the parent frame, then the attribute can be skipped
in the function call.
a data.frame.
## Not run: items |> adjust(config, item = "foo") ## End(Not run)## Not run: items |> adjust(config, item = "foo") ## End(Not run)
Launches the administration console.
admin()admin()
The Admin Console is a standalone Shiny web app delivered along with the package to administrate the items of the project.
It will check the R_KITEMS_PATH environment variable and look
for the YAML config file in the provided path.
## Not run: # set environment (where to find the _kitems.yml) Sys.setenv("R_KITEMS_PATH" = "D:/data") # launch the Admin Console admin() ## End(Not run)## Not run: # set environment (where to find the _kitems.yml) Sys.setenv("R_KITEMS_PATH" = "D:/data") # launch the Admin Console admin() ## End(Not run)
Update specific parameter(s) of specific attribute(s).
amend(config, item = get_context(), ...)amend(config, item = get_context(), ...)
config |
the config list. |
item |
the name (id) of the item group. |
... |
one or several attribute instructions. |
The function only understands attribute instruction.
It can handle multiple instructions in ....
Note that it is forbidden to update:
the id attribute (any parameter),
the name and/or type of an attribute.
When item is set in the parent frame, then the attribute can be skipped
in the function call.
a list
## Not run: # create baseline config <- design(project = "test", item = "foo") |> extend(item = "foo", attribute = c(name = "total", type = "integer")) # skip item argument (in the following calls) item <- "foo" # single instruction config |> amend(attribute = c(name = "total", default = 12)) config |> amend(attribute = c(name = "total", values = "suggest(12)")) # multiple instructions config |> amend(attribute = c(name = "total", values = "suggest(12)"), attribute = c(name = "total", default = "0")) ## End(Not run)## Not run: # create baseline config <- design(project = "test", item = "foo") |> extend(item = "foo", attribute = c(name = "total", type = "integer")) # skip item argument (in the following calls) item <- "foo" # single instruction config |> amend(attribute = c(name = "total", default = 12)) config |> amend(attribute = c(name = "total", values = "suggest(12)")) # multiple instructions config |> amend(attribute = c(name = "total", values = "suggest(12)"), attribute = c(name = "total", default = "0")) ## End(Not run)
Turn Item Into Default Value(s)
as_default(item, data.model)as_default(item, data.model)
item |
the data.frame of the item to use as a reference. |
data.model |
the data.frame of the data.model (see details). |
This function does not accept the data.model element of the config list as an input.
It should be turned into a data.frame first, using yaml_to_dm().
data.model should contain the following columns:
"name", "type", "default", "values".
item and data.model must have same structure. That means the names
of the attributes in the data model are expected to match with the names
of the columns in item.
a data.frame to pass to form() function.
## Not run: # create a config config <- design(project = "foo", item = "bar") | > extend(item = "bar", attribute = c(name = "date", type = "Date", default = "Sys.Date()") # get the default as_default(item, data.model = yaml_to_dm(config, "name", "type", "default", "values")) ## End(Not run)## Not run: # create a config config <- design(project = "foo", item = "bar") | > extend(item = "bar", attribute = c(name = "date", type = "Date", default = "Sys.Date()") # get the default as_default(item, data.model = yaml_to_dm(config, "name", "type", "default", "values")) ## End(Not run)
Build input for an attribute.
attribute_input( name, type, value = NULL, choices = NULL, create = FALSE, session = getDefaultReactiveDomain() )attribute_input( name, type, value = NULL, choices = NULL, create = FALSE, session = getDefaultReactiveDomain() )
name |
the name of the attribute. |
type |
the type of the attribute. |
value |
the value to be used to initialize the input. |
choices |
a list of values to select from (see details). |
create |
a logical (default = |
session |
optional, the shiny session object. |
By default (choices = NULL), the function will return an input driven by the
type of the attribute.
When choices are provided, it will be replaced by a selectizeInput. User
will be allowed to create additional values depending on create (otherwise ignored).
An input that can be added to the UI definition.
## Not run: # -- create inputs attribute_input(name = "total", type = "numeric", value = 10) ## End(Not run)## Not run: # -- create inputs attribute_input(name = "total", type = "numeric", value = 10) ## End(Not run)
Backup config, data model or items files.
backup( type = c("config", "items", "dm"), id = NULL, max = 1, path = Sys.getenv("R_KITEMS_PATH") )backup( type = c("config", "items", "dm"), id = NULL, max = 1, path = Sys.getenv("R_KITEMS_PATH") )
type |
the type of file to backup (see details). |
id |
the id of the item or data model. |
max |
an integer (default = 1) to indicate how many backup files are allowed. |
path |
optional, the path to the data. |
type accepts the following values:
"config" (the default)
"items"
"dm"
"dm" is kept to enable data.model backup before migration to the YAML config.
id will be ignored if type = "config"
The recommended way to define the path argument is to set the R_KITEMS_PATH
environment variable.
Backup file will be named as _kitems_YYYY-MM-DD.yml, id_data_model_YYYY-MM-DD.rds or id_items_YYYY-MM-DD.csv If same file already exists, it will be overwritten.
## Not run: # backup config backup() ## End(Not run)## Not run: # backup config backup() ## End(Not run)
Wrapper function to either check the YAML config or items integrity.
check(...)check(...)
... |
the object(s) to check (see details) |
The function is smart enough to detect what is passed to ....
To check the items, it is necessary to also pass the corresponding
id in the config (see examples).
a list
## Not run: # check config (list) config <- design(project = "test") check(config) # check items (data.frame) check(items, config, id = "foo") ## End(Not run)## Not run: # check config (list) config <- design(project = "test") check(config) # check items (data.frame) check(items, config, id = "foo") ## End(Not run)
Compute attribute values with data-masking support.
compute(x, data = NULL)compute(x, data = NULL)
x |
a character string of the expression to evaluate. |
data |
an optional data.frame to use for tidy evaluation of |
a vector of values.
## Not run: # baseline compute(x = "suggest(1, 2)") # with data masking compute(x = "suggest(min(value))", data = data.frame(value = c(12, 10))) ## End(Not run)## Not run: # baseline compute(x = "suggest(1, 2)") # with data masking compute(x = "suggest(min(value))", data = data.frame(value = c(12, 10))) ## End(Not run)
Action button(s) to fire the item dialog.
create_widget(id) update_widget(id) delete_widget(id) actions_widget(id)create_widget(id) update_widget(id) delete_widget(id) actions_widget(id)
id |
the server module id. |
id is the namespace of the module server instance holding
the target item.
create_widget() to fire create dialog
update_widget() to fire update dialog
delete_widget() to fire delete dialog
actions_widget() is a wrapper that returns all there buttons.
An HTML tag.
## Not run: # assuming the module server has been launched with id = "mydata" create_widget(id = "mydata") ## End(Not run)## Not run: # assuming the module server has been launched with id = "mydata" create_widget(id = "mydata") ## End(Not run)
The UI component to drive the date filter.
date_slider_widget(id, width = "300px", bootstrap = bslib::version_default())date_slider_widget(id, width = "300px", bootstrap = bslib::version_default())
id |
the server module id. |
width |
the width of the input (passed to |
bootstrap |
optional, a character string for the Bootstrap major version (see details). |
bootstrap has been added in version 0.8.0 to determine if bslib::popover() can be used
in the widget. The default is provided by bslib::version_default(), but there is no obvious
way to know - from the UI side - if the app uses shiny's default or bslib layouts.
In case you are using shiny's layout (ex: shiny::fluidPage()), you should set the parameter
to bootstrap = "3".
An HTML tag.
## Not run: # with bslib or Bootstrap 5 in general date_slider_widget(id = "mydata") # with Bootstrap 3 date_slider_widget(id = "mydata", bootstrap = "3") ## End(Not run)## Not run: # with bslib or Bootstrap 5 in general date_slider_widget(id = "mydata") # with Bootstrap 3 date_slider_widget(id = "mydata", bootstrap = "3") ## End(Not run)
Apply mask on attribute names.
decorate(x)decorate(x)
x |
a data.frame or named object |
The function makes the column names pretty.
A renamed data.frame or object.
## Not run: decorate(x = dm) ## End(Not run)## Not run: decorate(x = dm) ## End(Not run)
Compute default value(s).
default(data.model)default(data.model)
data.model |
the data.frame of the data model. |
This function does not accept the data.model element of the config list as an input.
It should be turned into a data.frame first, using yaml_to_dm().
data.model should contain the following columns:
"name", "type", "default" and "values".
A data.frame.
## Not run: # create a config config <- design(project = "foo", item = "bar") | > extend(item = "bar", attribute = c(name = "date", type = "Date", default = "Sys.Date()") # get the default default(yaml_to_dm(config, "name", "type", "default", "values")) ## End(Not run)## Not run: # create a config config <- design(project = "foo", item = "bar") | > extend(item = "bar", attribute = c(name = "date", type = "Date", default = "Sys.Date()") # get the default default(yaml_to_dm(config, "name", "type", "default", "values")) ## End(Not run)
Delete Item(s)
delete(items, id)delete(items, id)
items |
the data.frame of the items. |
id |
a vector of id(s) for the item(s) to delete. |
The function will drop unmatched id(s).
a data.frame.
## Not run: delete(items = myitems, id = 123456789) ## End(Not run)## Not run: delete(items = myitems, id = 123456789) ## End(Not run)
Design the project configuration.
design(...)design(...)
... |
one or several instruction(s) to execute (see details). |
design is the core function / verb when it comes to building configuration.
The function understands the following instructions passed to ...:
project to create a config from scratch
item to add an item group to the project config
attribute to add an attribute to a given item group.
An instruction is always formed of a key (project, item or attribute) and
a value. The value can either be a length-one character string or a named
character vector.
The project = "test" instruction is used in almost all function documentation
examples to init a project config.
item = "foo" or item = c(id = "foo", description = "not bar") are used
to add an item group to the project.
attribute = c(item = "foo", name = "value", type = "integer") creates an
attribute named 'value' that will accept integers inside the item group 'foo'.
Multiple instructions are supported as recursion is implemented (the function can call itself to execute each instruction and merge the outputs).
As the package grammar is designed for a layered approach, design only covers
attribute creation without fine tuning.
This means it creates attribute(s) with name & type only.
use extend to create an attribute with fine tuning.
use hide, display, skip, include & refresh to set specific
attribute behaviors.
In addition to the named instructions, a single unnamed argument is accepted
among ... to support piping from the config object (see examples).
If multiple unnamed objects are passed, an error will be thrown.
a list.
## Not run: # create project config from scratch config <- design(project = "foo") # add (single) item group config |> design(item = "foo") config |> design(item = c(id = "foo", description = "x")) # add (multiple) item groups config |> design(item = "foo", item = "bar") config |> design(item = c(id = "foo", description = "x"), item = c(id = "bar", description = "z")) config |> design(item = c(id = "foo", description = "x"), item = "bar") # add (single) attribute to item group config |> design(item = "foo", attribute = c(item = "foo", name = "value", type = "integer")) # add (multiple) attributes to item group config |> design(item = "foo", attribute = c(item = "foo", name = "value", type = "integer"), attribute = c(item = "foo", name = "comment", type = "character")) # if instruction is not understood design(dream = "draw me a sheep") ## End(Not run)## Not run: # create project config from scratch config <- design(project = "foo") # add (single) item group config |> design(item = "foo") config |> design(item = c(id = "foo", description = "x")) # add (multiple) item groups config |> design(item = "foo", item = "bar") config |> design(item = c(id = "foo", description = "x"), item = c(id = "bar", description = "z")) config |> design(item = c(id = "foo", description = "x"), item = "bar") # add (single) attribute to item group config |> design(item = "foo", attribute = c(item = "foo", name = "value", type = "integer")) # add (multiple) attributes to item group config |> design(item = "foo", attribute = c(item = "foo", name = "value", type = "integer"), attribute = c(item = "foo", name = "comment", type = "character")) # if instruction is not understood design(dream = "draw me a sheep") ## End(Not run)
Produces a create / update / delete modal dialog.
dialog( ..., workflow = c("create", "update", "delete"), session = getDefaultReactiveDomain() )dialog( ..., workflow = c("create", "update", "delete"), session = getDefaultReactiveDomain() )
... |
the content to be displayed in the modal dialog. |
workflow |
a character string to indicate workflow (see details). |
session |
optional, the shiny session object. |
Possible values for workflow are "create" (default), "update" or "delete".
... is typically the output of the form() function.
When workflow = "delete", it will be ignored and replaced by a standard message.
a modal dialog.
## Not run: dialog(workflow = "delete") ## End(Not run)## Not run: dialog(workflow = "delete") ## End(Not run)
Execute the migration procedure on a data model.
dm_migrate(data.model)dm_migrate(data.model)
data.model |
a data.frame of the data model. |
The migrated data model or NA if no migration is required.
## Not run: dm_migrate(data.model) ## End(Not run)## Not run: dm_migrate(data.model) ## End(Not run)
Convert data model to YAML configuration file.
dm_to_yaml(dm)dm_to_yaml(dm)
dm |
a data.frame of the data model |
The input data model should have its version = "0.8.0" otherwise an error
will be raised. Use dm_migrate() first if needed.
a list.
## Not run: dm_to_yaml(dm) ## End(Not run)## Not run: dm_to_yaml(dm) ## End(Not run)
Add attribute to existing items.
enforce(items, name, type, fill = NA)enforce(items, name, type, fill = NA)
items |
a data.frame of the items. |
name |
a character string of the attribute name. |
type |
a character string of the attribute type. |
fill |
the value (default = |
fill will be coerced to the class name provided in type.
If a vector is given as input for fill, it will be used to feed the created column.
Make sure the vector length is same as the number of rows, otherwise an error will be raised by R.
The updated items data.frame.
## Not run: enforce(items = myitems, name = "comment", type = "character", fill = "none") ## End(Not run)## Not run: enforce(items = myitems, name = "comment", type = "character", fill = "none") ## End(Not run)
Add specific attribute(s) with fine tuning.
extend(config, item = get_context(), ...)extend(config, item = get_context(), ...)
config |
the config object. |
item |
the name (id) of the item group. |
... |
one or several attribute instructions. |
This function is a wrapper around design() to provide a comprehensive
layered syntax.
It only understands the attribute instruction inside ...:
attribute = c(name = "note", type = "character")
Anything else will be filtered.
When item is set in the parent frame, then the parameter can be skipped
in the function call.
a list.
## Not run: # create config config <- design(project = "test", item = "foo") # set item (to skip it in following calls) item <- "foo" # extend config |> extend(attribute = c(name = "date", type = "Date", default = "Sys.Date()")) # is same as config <- design(project = "test", item = "foo", attribute = c(name = "date", type = "Date", default = "Sys.Date()")) ## End(Not run)## Not run: # create config config <- design(project = "test", item = "foo") # set item (to skip it in following calls) item <- "foo" # extend config |> extend(attribute = c(name = "date", type = "Date", default = "Sys.Date()")) # is same as config <- design(project = "test", item = "foo", attribute = c(name = "date", type = "Date", default = "Sys.Date()")) ## End(Not run)
Extract the list of values from the input.
extract(input, colClasses)extract(input, colClasses)
input |
the input object from the shiny module. |
colClasses |
a named vector of classes, defining the data model. |
The output list will contain as many entries as the colClasses named vector.
In case some names have no corresponding item in the input parameter, they
will get NULL as value in the output list.
a named list.
## Not run: values <- extract(input, colClasses = c("date" = "Date", "text" = "character")) ## End(Not run)## Not run: values <- extract(input, colClasses = c("date" = "Date", "text" = "character")) ## End(Not run)
Helper function to create filter events to be passed to kitems module server with the filter argument.
filter_event(layer = c("pre", "main"), ...)filter_event(layer = c("pre", "main"), ...)
layer |
the filter layer ("pre" or "main"). |
... |
the expression(s) to pass to the filter. |
When no expression is passed to ... then the filter layer will be reset.
See the module server function to know how to pass the event to the module server.
For more details see this vignette:
vignette("filtering", package = "kitems")
A list.
## Not run: # set pre-filtering layer filter_event(layer = "pre", expr = name == Banana) # reset main filter filter_event(layer = "main") ## End(Not run)## Not run: # set pre-filtering layer filter_event(layer = "pre", expr = name == Banana) # reset main filter filter_event(layer = "main") ## End(Not run)
Builds the create or update item form.
form(attributes, items = NULL)form(attributes, items = NULL)
attributes |
a data.frame of the attributes (see details). |
items |
an optional data.frame of the items (see details). |
attributes is expected to be the output of the default() or as_default() function.
The data.frame should have the following columns:
"name", "type", "default", "values".
items are required only when the attribute values defined in the data.model
should be evaluated with data masking support.
A list of HTML tags.
## Not run: form(attributes = data.frame(name = "total", type = "numeric")) ## End(Not run)## Not run: form(attributes = data.frame(name = "total", type = "numeric")) ## End(Not run)
Basic check if item has a 'date' attribute.
has_date_attribute(config, item = get_context())has_date_attribute(config, item = get_context())
config |
the config list |
item |
the name (id) of the item group |
When item is set in the parent frame, then the attribute can be skipped
in the function call.
a logical
has_date_attribute(design(project = "test"))has_date_attribute(design(project = "test"))
A set of verbs to manipulate the display of an attribute.
hide(config, item = get_context(), ...) display(config, item = get_context(), ...) hidden(config, item = get_context()) displayed(config, item = get_context())hide(config, item = get_context(), ...) display(config, item = get_context(), ...) hidden(config, item = get_context()) displayed(config, item = get_context())
config |
the config list. |
item |
the name (id) of the item group. |
... |
the name of the attribute(s) to manipulate. |
hide() and display() are setter functions to tune attribute's behavior.
hidden() and displayed() are getter functions to quickly access the attributes
to hide or display in the item table.
When item is set in the parent frame, then the attribute can be skipped
in the function call.
a list (setters) or a character vector (getters).
## Not run: # hide attribute config <- design(project = "test", item = "foo") |> extend(item = "foo", attribute = c(name = "date", type = "Date")) |> hide(item = "foo", "date") # allow skipping argument in following calls item <- "foo" # hidden attributes config |> hidden() # display attribute config |> display("date") # displayed attributes config |> displayed() ## End(Not run)## Not run: # hide attribute config <- design(project = "test", item = "foo") |> extend(item = "foo", attribute = c(name = "date", type = "Date")) |> hide(item = "foo", "date") # allow skipping argument in following calls item <- "foo" # hidden attributes config |> hidden() # display attribute config |> display("date") # displayed attributes config |> displayed() ## End(Not run)
Insert Item(s)
insert(values, items)insert(values, items)
values |
a data.frame of item(s) to insert. |
items |
a data.frame of items where to insert. |
The function is mostly a wrapper around dplyr::bind_rows() function.
It does check for potential duplicates among the 'id' column. If so, the operation will be aborted as there is no way to know how to fix the duplicated id(s).
a data.frame.
## Not run: insert(values, items) ## End(Not run)## Not run: insert(values, items) ## End(Not run)
Inspired by shiny::isTruthy(), the purpose here is to determine if a value
is considered as valid to be an attribute value.
(or if it will need to be replaced by the attribute defaults).
is_truthy(x)is_truthy(x)
x |
an object to test. |
A logical.
is_truthy(12)is_truthy(12)
Load Items
item_load(connector, col.classes)item_load(connector, col.classes)
connector |
a list that will be passed to |
col.classes |
a named vector containing the expected column types. |
The data.frame of the items.
## Not run: # -- File connector: item_load(col.classes = c(id = "numeric", date = "Date", comment = "character"), connector = list(type = "file", path = "path/to/my/data", filename = "mydata.csv")) ## End(Not run)## Not run: # -- File connector: item_load(col.classes = c(id = "numeric", date = "Date", comment = "character"), connector = list(type = "file", path = "path/to/my/data", filename = "mydata.csv")) ## End(Not run)
Saves the items data.frame.
item_save(data, connector)item_save(data, connector)
data |
a data.frame containing the data to be saved. |
connector |
a list that will be passed to |
## Not run: # -- File connector: item_save(data = mydata, connector = list(type = "file", file = "path/to/my/data/mydata.csv")) ## End(Not run)## Not run: # -- File connector: item_save(data = mydata, connector = list(type = "file", file = "path/to/my/data/mydata.csv")) ## End(Not run)
The UI component for the item table.
item_widget(id)item_widget(id)
id |
the id of the module server instance. |
An HTML tag.
## Not run: item_widget(id = "mydata") ## End(Not run)## Not run: item_widget(id = "mydata") ## End(Not run)
This function is part of the selective loading mechanism to ensure items are loaded only when required.
items(datamart, config, item)items(datamart, config, item)
datamart |
a reactiveValues object holding the items. |
config |
the config list. |
item |
the name (id) of the item group. |
a data.frame of the items or NULL.
## Not run: # init the datamart datamart <- reactiveValues() # get items (it will load them) datamart |> items("foo") # get them again (already loaded) datamart |> items("foo") ## End(Not run)## Not run: # init the datamart datamart <- reactiveValues() # get items (it will load them) datamart |> items("foo") # get them again (already loaded) datamart |> items("foo") ## End(Not run)
This is the main component of the package.
kitems( id, path = Sys.getenv("R_KITEMS_PATH"), trigger = NULL, filter = NULL, options = list(autosave = TRUE, notify = TRUE) )kitems( id, path = Sys.getenv("R_KITEMS_PATH"), trigger = NULL, filter = NULL, options = list(autosave = TRUE, notify = TRUE) )
id |
the unique id of the module server instance. |
path |
where the YALM config and items are stored (see details). |
trigger |
an optional reactive object to pass workflow events (see details). |
filter |
an optional reactive object to pass filter events (see details). |
options |
an optional list of options (see details). |
Since version 0.8.0, the recommended way to define the path argument is
to set the R_KITEMS_PATH environment variable.
If directly passed as an argument value, a warning will be raised at the console.
Behavior of the module server can be tuned using a list of options:
autosave is a logical whether the item auto save should be activated or not (default = TRUE)
notify is a logical if Shiny notifications should be displayed (default = TRUE)
Partial lists are supported, with missing elements getting the default value.
If autosave option is FALSE, the item_save() function should be used
to make the data persistent.
Triggers are the way to send events for the module to execute dedicated actions.
trigger must be a reactive (or NULL, the default).
An event is defined as a named list (see examples) and may be created
using the trigger_event() function.
If NULL, the trigger manager will not be initialized.
filter is a reactive object reference to pass filter expression(s) to the module server
A filter is defined as a named list (see examples).
It may be created using the filter_event() helper function.
If NULL, the filter manager will not be initialized.
a list
Details about the elements of this list:
id = the id of the module (same as the input)
items = the reference of the items reactive object
data_model = a list, describing the item's data model
filtered_items = the reference of the filtered items reactive object
selected_items = the reference of the selected items (ids) reactive object
clicked_column = the reference of the clicked column reactive object
filters = the reference of the reactive list with filter expressions.
trigger_event(), filter_event()
## Not run: # baseline: # launch module server to handle item group named "foo" kitems(id = "foo") # read only: kitems(id = "foo", options = list(autosave = FALSE)) # trigger: # pass workflow events to the module server trigger <- reactiveVal() kitems(id = "foo", trigger = trigger) # fire the create item dialog: trigger(list(workflow = "create", type = "dialog")) # fire an item creation (no dialog): # assuming 'foo' item has a 'name' character attribute trigger(list(workflow = "create", type = "task", values = list(name = "test"))) # filter: # pass filter events to the module server filter <- reactiveVal() kitems(id = "foo", filter = filter) # apply filter at the pre-filtering layer # assuming item 'foo' has a 'total' numeric attribute filter(list(layer = "pre", expr = total > 10)) ## End(Not run)## Not run: # baseline: # launch module server to handle item group named "foo" kitems(id = "foo") # read only: kitems(id = "foo", options = list(autosave = FALSE)) # trigger: # pass workflow events to the module server trigger <- reactiveVal() kitems(id = "foo", trigger = trigger) # fire the create item dialog: trigger(list(workflow = "create", type = "dialog")) # fire an item creation (no dialog): # assuming 'foo' item has a 'name' character attribute trigger(list(workflow = "create", type = "task", values = list(name = "test"))) # filter: # pass filter events to the module server filter <- reactiveVal() kitems(id = "foo", filter = filter) # apply filter at the pre-filtering layer # assuming item 'foo' has a 'total' numeric attribute filter(list(layer = "pre", expr = total > 10)) ## End(Not run)
Helper function to homogenize names across the package.
name( id = NULL, what = c("item", "dm", "config"), file = FALSE, url = FALSE, backup = FALSE )name( id = NULL, what = c("item", "dm", "config"), file = FALSE, url = FALSE, backup = FALSE )
id |
the name (id) of the item group. |
what |
the targeted object (item, dm or config). |
file |
a logical if file extension should be added. |
url |
a logical if the url should be returned. |
backup |
a logical if a timestamp should be added. |
what accepts "dm" for backward compatibility reasons (backup & restore old
data.model files before migration to YAML config).
When url is TRUE, then file is considered TRUE as well.
When backup is TRUE, then file is considered TRUE as well.
Note that from v0.8.0 url for the config is build from the
R_KITEMS_PATH environment variable and url for the item groups
is contained in the YAML config.
a character string.
# item name name("foo")# item name name("foo")
Set or get sorting order.
organize(config, item = get_context(), sort) organized(config, item = get_context())organize(config, item = get_context(), sort) organized(config, item = get_context())
config |
the config list. |
item |
the name (id) of the item group. |
sort |
a character string to set the order (see details). |
The organize function accepts a character string for sort because it is
primarily intended to deal with the Admin Console (which returns
a character string from the user input).
Setting sort = NULL will reset the item sorting!
Ranking depends on the position of the attribute. Wrap attribute name by "desc()" to set descending order.
When item is set in the parent frame, then the attribute can be skipped
in the function call.
organize returns a list and
organized returns a character string
## Not run: organize(config, item = "foo", sort = "date, desc(total)") organize(config, item = "foo", sort = NULL) ## End(Not run)## Not run: organize(config, item = "foo", sort = "date, desc(total)") organize(config, item = "foo", sort = NULL) ## End(Not run)
Turn trigger values into tabular data.
prepare(values, config, update = FALSE, item = get_context())prepare(values, config, update = FALSE, item = get_context())
values |
a named list of values (see details). |
config |
the config list. |
update |
a logical if values are used in the update workflow (default |
item |
optional (see details), the name (id) of the item group. |
values is a named list. The names are used to check the corresponding values
vs the data.model (class, default values if the provided ones are not valid).
The elements in the list must have either length one or same length as the id element.
When an element has length one but the id has several values, all items corresponding
to these ids will be updated with same value. To do so, values will be turned into
a data.frame using as.data.frame ; for this reason, it's strongly advised to wrap
the call into tryCatch() as this may fail.
When item is set in the parent frame, then the attribute can be skipped
in the function call.
a data.frame
## Not run: prepare(values, config, item = "foo") ## End(Not run)## Not run: prepare(values, config, item = "foo") ## End(Not run)
A set of verbs to manipulate the refreshed attribute(s) of an item.
refresh(config, item = get_context(), ...) freeze(config, item = get_context(), ...) refreshed(config, item = get_context()) frozen(config, item = get_context())refresh(config, item = get_context(), ...) freeze(config, item = get_context(), ...) refreshed(config, item = get_context()) frozen(config, item = get_context())
config |
the config list. |
item |
the name (id) of the item group. |
... |
the name of the attribute(s) to manipulate. |
refresh() and freeze() are setter functions that allow to add or remove
attributes from the refreshed ones.
refreshed() and frozen() are getter functions to quickly access the skipped
attributes that are refreshed or not during an item update.
Trying to refresh an attribute that is not skipped will be ignored without a warning.
When item is set in the parent frame, then the attribute can be skipped
in the function call.
a list (setters) or a character vector (getters).
## Not run: # refresh attribute config <- design(project = "test", item = "foo") |> extend(item = "foo", attribute = c(name = "date", type = "Date")) |> skip(item = "foo", "date") |> refresh(item = "foo", "date") # refreshed attributes config |> refreshed(item = "foo") # freeze attribute config |> freeze(item = "foo", "date") # frozen attributes config |> frozen(item = "foo") ## End(Not run)## Not run: # refresh attribute config <- design(project = "test", item = "foo") |> extend(item = "foo", attribute = c(name = "date", type = "Date")) |> skip(item = "foo", "date") |> refresh(item = "foo", "date") # refreshed attributes config |> refreshed(item = "foo") # freeze attribute config |> freeze(item = "foo", "date") # frozen attributes config |> frozen(item = "foo") ## End(Not run)
Restore config, data model or items files.
restore( type = c("config", "items", "dm"), id = NULL, path = Sys.getenv("R_KITEMS_PATH") )restore( type = c("config", "items", "dm"), id = NULL, path = Sys.getenv("R_KITEMS_PATH") )
type |
the type of file to restore (see details). |
id |
the id for data.model & items. |
path |
optional, the path to the data. |
type accepts the following values:
"config" (the default)
"items"
"dm"
When "config" is used, id is ignored.
"dm" is kept for compatibility purpose.
The recommended way to define the path argument is to set the R_KITEMS_PATH
environment variable.
In case several backup files exist, the newest one will be restored.
a logical (see file.copy())
## Not run: restore() restore(type = "items", id = "foo") ## End(Not run)## Not run: restore() restore(type = "items", id = "foo") ## End(Not run)
Apply data model display mask on the items.
reveal(items, config, item = get_context())reveal(items, config, item = get_context())
items |
the data.frame of the items. |
config |
the config list. |
item |
the name (id) of the item group. |
The data model display mask is defined at the data.model level.
use hide() or display() to tune it.
When item is set in the parent frame, then the attribute can be skipped
in the function call.
A data.frame.
[hide()][display()][parent.frame()]
## Not run: # assuming config has been declared and # items is the data.frame of the items item <- "foo" items |> reveal(config) ## End(Not run)## Not run: # assuming config has been declared and # items is the data.frame of the items item <- "foo" items |> reveal(config) ## End(Not run)
Run Shiny Demo Apps
runExample(example = NA)runExample(example = NA)
example |
a character value, with the name of the demo to be launched. |
When example is NA, the function will return the names of available apps.
## Not run: runExample() ## End(Not run)## Not run: runExample() ## End(Not run)
Shrink Config
shrink(config, ...)shrink(config, ...)
config |
the config list. |
... |
one or several item or attribute instruction. |
Drop an item or an attribute from the config.
The function understands the following instructions:
item = foo
attribute = c(item = "foo", name = "total")
See the examples for more details.
It supports multiple instructions.
Note that it is forbidden to delete the 'id' attribute of an item.
a list.
## Not run: # build baseline config <- design(project = "test", item = "foo") |> extend(item = "foo", attribute = c(name = "total", type = "integer")) # drop item config |> shrink(item = "foo") # drop attribute config |> shrink(attribute = c(item = "foo", name = "total")) # multiple instructions config |> shrink(attribute = c(item = "foo", name = "total"), item = "foo") ## End(Not run)## Not run: # build baseline config <- design(project = "test", item = "foo") |> extend(item = "foo", attribute = c(name = "total", type = "integer")) # drop item config |> shrink(item = "foo") # drop attribute config |> shrink(attribute = c(item = "foo", name = "total")) # multiple instructions config |> shrink(attribute = c(item = "foo", name = "total"), item = "foo") ## End(Not run)
A set of verbs to manipulate the skipped attribute(s) of an item.
skip(config, item = get_context(), ...) include(config, item = get_context(), ...) skipped(config, item = get_context()) included(config, item = get_context())skip(config, item = get_context(), ...) include(config, item = get_context(), ...) skipped(config, item = get_context()) included(config, item = get_context())
config |
the config list. |
item |
the name (id) of the item group. |
... |
the name of the attribute(s) to manipulate. |
skip() and include() are setter functions that allow to add or remove
attributes from the skipped ones.
skipped() and included() are getter functions to quickly access the attributes
that are skipped or included in the item form.
In a scenario where items are created programmatically, included() may be used
to determine what values can be sent to the trigger.
When item is set in the parent frame, then the attribute can be skipped
in the function call.
a list (setters) or a character vector (getters).
## Not run: # skip attribute config <- design(project = "test", item = "foo") |> extend(item = "foo", attribute = c(name = "date", type = "Date")) |> skip(item = "foo", "date") # get skipped attributes config |> skipped(item = "foo") # include attribute config |> include(item = "foo", "date") # get included attributes config |> included(item = "foo") ## End(Not run)## Not run: # skip attribute config <- design(project = "test", item = "foo") |> extend(item = "foo", attribute = c(name = "date", type = "Date")) |> skip(item = "foo", "date") # get skipped attributes config |> skipped(item = "foo") # include attribute config |> include(item = "foo", "date") # get included attributes config |> included(item = "foo") ## End(Not run)
Helper function to create events to be passed to kitems module server
with the trigger argument.
trigger_event( workflow = c("create", "update", "delete"), type = c("dialog", "task"), values = NULL )trigger_event( workflow = c("create", "update", "delete"), type = c("dialog", "task"), values = NULL )
workflow |
the name of the workflow (create, update or delete). |
type |
the name of the action to be performed (dialog or task). |
values |
optional list of values to create, update or delete an item. |
The function also adds an event id to make it unique (otherwise sending two times the same request would fail).
For more details see this vignette:
vignette("workflows", package = "kitems")
A list.
## Not run: # create dialog event trigger_event() # delete item event (without dialog) trigger_event(workflow = "delete", type = "task", values = list(id = 1234)) ## End(Not run)## Not run: # create dialog event trigger_event() # delete item event (without dialog) trigger_event(workflow = "delete", type = "task", values = list(id = 1234)) ## End(Not run)
Update Item(s)
update(values, items)update(values, items)
values |
a data.frame used to update the items. |
items |
a data.frame of the items. |
The function will drop unmatched id(s) in values.
a data.frame.
## Not run: update(values, items) ## End(Not run)## Not run: update(values, items) ## End(Not run)
Validate values and turn them into item(s).
validate(values, data.model, items = NULL, update = FALSE)validate(values, data.model, items = NULL, update = FALSE)
values |
a list of named values. |
data.model |
the data.frame of the data model (see details). |
items |
an optional data.frame of the items (see details). |
update |
whether the id attribute should be checked or not (default |
This function does not accept the data.model element of the config list as an input.
It should be turned into a data.frame first, using yaml_to_dm().
data.model should contain the following columns:
"name", "type", "default", "class.arg", "values".
In case the data.model values column contains instruction that require
data-masking, items will be used as a context to evaluate those instructions.
A data.frame.
## Not run: # create config config <- design(project = "test", item = "foo") |> extend(item = "foo", attribute = list(name = "name", type = "character"), attribute = list(name = "quantity", type = "numeric")) # values values <- list(name = c("Banana", "Mango"), quantity = c(1, 12)) # call function validate(values, data.model = yaml_to_dm(config, "name", "type", "default", "class.arg", "values")) ## End(Not run)## Not run: # create config config <- design(project = "test", item = "foo") |> extend(item = "foo", attribute = list(name = "name", type = "character"), attribute = list(name = "quantity", type = "numeric")) # values values <- list(name = c("Banana", "Mango"), quantity = c(1, 12)) # call function validate(values, data.model = yaml_to_dm(config, "name", "type", "default", "class.arg", "values")) ## End(Not run)
Turn a config list into a data.frame.
yaml_to_dm(config, ..., item = get_context())yaml_to_dm(config, ..., item = get_context())
config |
the config list (see details). |
... |
the columns to include in the output. |
item |
the name (id) of the item group. |
The function is used as a bridge between the config list structure and the expected data.frame input argument for some functions.
It also helps to keep / select the desired columns.
Pass the column names (quoted or unquoted) to ....
Note that if the function is used inside a package (kitems does), then
the column names should be quoted or R-CMD Check will throw a note about
'no visible binding for global variable' since the column names are not
declared as symbol in the environment.
By default, config is the global project config list.
item is required in this case unless it is already set in the parent
frame.
In case the item level config list is provided, it should be up to
the data.model's level. Make sure to explicitly set ìtem = NULL if
it is set in the parent frame.
a data.frame
## Not run: # get data.model with name and default yaml_to_dm(config, name, default, item = "foo") ## End(Not run)## Not run: # get data.model with name and default yaml_to_dm(config, name, default, item = "foo") ## End(Not run)