Module to render R Markdown files using the data provided in the
teal_data object.
The R Markdown file should be designed to accept variables available in the data names of the module.
Arguments
- label
(
character(1)) Label shown in the navigation item for the module or module group. Formodules()defaults to"root". SeeDetails.- rmd_content
(
character) Content of the R Markdown file to be rendered. This can be the value ofreadLines("path/to/file.Rmd").- datanames
-
(
character) Names of the datasets relevant to the item. There are 2 reserved values that have specific behaviors:The keyword
"all"includes all datasets available in the data passed to the teal application.NULLhides the sidebar panel completely.If
transformatorsare specified, theirdatanamesare automatically added to thisdatanamesargument.
- allow_download
(
logical) whether to allow downloading of the R Markdown file. Defaults toTRUE.- pre_output
(
shiny.tag) optional, text or UI element to be displayed before the module's output, providing context or a title. with text placed before the output to put the output into context. For example a title.- post_output
(
shiny.tag) optional, text or UI element to be displayed after the module's output, adding context or further instructions. Elements likeshiny::helpText()are useful.- transformators
(
listofteal_transform_module) that will be applied to transform module's data input. To learn more checkvignette("transform-input-data", package = "teal").- extra_transform
(
list) ofteal::teal_transform_module()that will be added in the module's UI. This can be used to create interactive inputs that modify the parameters in R Markdown rendering.
Details
For example, if the teal_data object contains datasets named mtcars
and iris, the R Markdown file can use these as variables as they
will be available in the R Markdown environment.
The libraries used in the R Markdown file must be available in the deployed shiny app environment.
When developing the R Markdown file, the working data can be simulated
on a code chunk, which in turn can look for the presence of .raw_data
object to determine if it is being run inside the teal module or not.
Example R markdown file:
Reporting
This module returns an object of class teal_module, that contains a server function.
Since the server function returns a teal_report object, this makes this module reportable, which means that
the reporting functionality will be turned on automatically by the teal framework.
For more information on reporting in teal, see the vignettes:
vignette("reportable-shiny-application", package = "teal.reporter")vignette("adding-support-for-reporting-to-custom-modules", package = "teal")
Examples
# general data example
data <- teal_data()
data <- within(data, {
CO2 <- CO2
})
app <- init(
data = data,
modules = modules(
tm_rmarkdown(
label = "RMarkdown Module",
rmd_content = c(
"---",
"title: \"R Markdown Report\"",
"output: html_document",
"---",
"",
"```{r}",
"summary(CO2) |> print()",
"```"
)
)
)
)
#> Initializing tm_rmarkdown
if (interactive()) {
shinyApp(app$ui, app$server)
}
nrow_transform <- teal_transform_module(
label = "N Rows selector",
ui = function(id) {
ns <- NS(id)
tags$div(
numericInput(ns("n_rows"), "Show n rows", value = 40, min = 0, max = 200, step = 5)
)
},
server = function(id, data) {
moduleServer(id, function(input, output, session) {
reactive({
req(data())
within(data(),
{
n_rows <- n_rows_value
},
n_rows_value = input$n_rows
)
})
})
}
)
app <- init(
data = data,
modules = modules(
tm_rmarkdown(
label = "RMarkdown Module",
rmd_content = readLines(
system.file(
file.path("sample_files", "co2_example.Rmd"),
package = "teal.modules.general"
)
),
allow_download = FALSE,
extra_transform = list(nrow_transform)
)
)
)
#> Initializing tm_rmarkdown
if (interactive()) {
shinyApp(app$ui, app$server)
}