View source: R/teal_data_module.R
teal_data_module | R Documentation |
teal
applicationsCreate a teal_data_module
object and evaluate code on it with history tracking.
teal_data_module(ui, server)
## S4 method for signature 'teal_data_module,character'
eval_code(object, code)
## S3 method for class 'teal_data_module'
within(data, expr, ...)
ui |
( |
server |
( |
object |
( |
code |
( |
data |
( |
expr |
( |
... |
See |
teal_data_module
creates a shiny
module to supply or modify data in a teal
application.
The module allows for running data pre-processing code (creation and some modification) after the app starts.
The body of the server function will be run in the app rather than in the global environment.
This means it will be run every time the app starts, so use sparingly.
Pass this module instead of a teal_data
object in a call to init()
.
Note that the server function must always return a teal_data
object wrapped in a reactive expression.
See vignette vignette("data-as-shiny-module", package = "teal")
for more details.
eval_code
evaluates given code in the environment of the teal_data
object created by the teal_data_module
.
The code is added to the @code
slot of the teal_data
.
within
is a convenience function for evaluating inline code inside the environment of a teal_data_module
.
It accepts only inline expressions (both simple and compound) and allows for injecting values into expr
through
the ...
argument: as name:value
pairs are passed to ...
, name
in expr
will be replaced with value.
teal_data_module
returns an object of class teal_data_module
.
eval_code
returns a teal_data_module
object with a delayed evaluation of code
when the module is run.
within
returns a teal_data_module
object with a delayed evaluation of expr
when the module is run.
teal.data::teal_data
, teal.code::qenv()
tdm <- teal_data_module(
ui = function(id) {
ns <- NS(id)
actionButton(ns("submit"), label = "Load data")
},
server = function(id) {
moduleServer(id, function(input, output, session) {
eventReactive(input$submit, {
data <- within(
teal_data(),
{
dataset1 <- iris
dataset2 <- mtcars
}
)
datanames(data) <- c("dataset1", "dataset2")
data
})
})
}
)
eval_code(tdm, "dataset1 <- subset(dataset1, Species == 'virginica')")
within(tdm, dataset1 <- subset(dataset1, Species == "virginica"))
# use additional parameter for expression value substitution.
valid_species <- "versicolor"
within(tdm, dataset1 <- subset(dataset1, Species %in% species), species = valid_species)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.