| tm_rmarkdown | R Documentation |
teal module: R Markdown renderModule 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.
tm_rmarkdown(
label = "RMarkdown Module",
rmd_content,
datanames = "all",
allow_download = TRUE,
pre_output = NULL,
post_output = NULL,
transformators = list(),
extra_transform = list()
)
label |
( |
rmd_content |
( |
datanames |
(
|
allow_download |
( |
pre_output |
( |
post_output |
( |
transformators |
( |
extra_transform |
( |
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:
---
title: "R Markdown Report"
output: html_document
---
```{r eval=!exists(".raw_data")}
mtcars <- datasets::mtcars
iris <- datasets::iris
```
```{r}
summary(mtcars) |> print()
summary(iris) |> print()
```
Object of class teal_module to be used in teal applications.
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")
# 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()",
"```"
)
)
)
)
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)
)
)
)
if (interactive()) {
shinyApp(app$ui, app$server)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.