This R6 class that supports creating a report card containing text, plot, table and
metadata blocks that can be appended and rendered to form a report output from a shiny app.
For more information about the various blocks, refer to the vignette:
vignette("teal-reporter-blocks-overview", "teal.reporter").
new()Initialize a ReportCard object.
ReportCard$new()card <- ReportCard$new()
append_table()Appends a table to this ReportCard.
tableA (data.frame or rtables or TableTree or ElementaryTable or listing_df)
that can be coerced into a table.
card <- ReportCard$new()$append_table(iris)
append_html()Appends a html content to this ReportCard.
card <- ReportCard$new()$append_html(shiny::div("HTML Content"))
append_plot()Appends a plot to this ReportCard.
append_text()Appends a text paragraph to this ReportCard.
ReportCard$append_text(text, style = TextBlock$new()$get_available_styles()[1])text(character) The text content to add.
style(character(1)) the style of the paragraph. One of: default, header2, header3, verbatim.
card <- ReportCard$new()$append_text("A paragraph of default text")
append_rcode()Appends an R code chunk to ReportCard.
text(character) The R code to include.
...Additional rmarkdown parameters for formatting the R code chunk.
card <- ReportCard$new()$append_rcode("2+2", echo = FALSE)
append_content()Appends a generic ContentBlock to this ReportCard.
NewpageBlock <- getFromNamespace("NewpageBlock", "teal.reporter")
card <- ReportCard$new()$append_content(NewpageBlock$new())
get_content()Get all content blocks from this ReportCard.
list() list of TableBlock, TextBlock and PictureBlock.
card <- ReportCard$new()$append_text("Some text")$append_metadata("rc", "a <- 2 + 2")
card$get_content()
get_metadata()Get the metadata associated with ReportCard.
card <- ReportCard$new()$append_text("Some text")$append_metadata("rc", "a <- 2 + 2")
card$get_metadata()
append_metadata()Appends metadata to this ReportCard.
get_name()Get the name of the ReportCard.
ReportCard$new()$set_name("NAME")$get_name()set_name()Set the name of the ReportCard.
ReportCard$new()$set_name("NAME")$get_name()from_list()Reconstructs the ReportCard from a list representation.
library(ggplot2)
card <- ReportCard$new()$append_plot(
ggplot(iris, aes(x = Petal.Length)) + geom_histogram()
)
#> `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
library(ggplot2)
card <- ReportCard$new()$append_text("Some text")$append_plot(
ggplot(iris, aes(x = Petal.Length)) + geom_histogram()
)$append_text("Some text")$append_metadata(key = "lm",
value = lm(Ozone ~ Solar.R, airquality))
#> `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
card$get_content()
#> [[1]]
#> <TextBlock>
#> Inherits from: <ContentBlock>
#> Public:
#> clone: function (deep = FALSE)
#> from_list: function (x)
#> get_available_styles: function ()
#> get_content: function ()
#> get_style: function ()
#> initialize: function (content = character(0), style = private$styles[1])
#> set_content: function (content)
#> set_style: function (style)
#> to_list: function ()
#> Private:
#> content: Some text
#> deep_clone: function (name, value)
#> style: default
#> styles: default header2 header3 verbatim
#>
#> [[2]]
#> <PictureBlock>
#> Inherits from: <FileBlock>
#> Public:
#> clone: function (deep = FALSE)
#> from_list: function (x, output_dir)
#> get_content: function ()
#> get_dim: function ()
#> get_title: function ()
#> initialize: function (plot)
#> set_content: function (content)
#> set_dim: function (dim)
#> set_title: function (title)
#> to_list: function (output_dir)
#> Private:
#> content: /tmp/RtmpN84x74/file2222372b76552.png
#> deep_clone: function (name, value)
#> dim: 800 600
#> finalize: function ()
#> supported_plots: ggplot grob trellis Heatmap
#> title:
#> type:
#>
#> [[3]]
#> <TextBlock>
#> Inherits from: <ContentBlock>
#> Public:
#> clone: function (deep = FALSE)
#> from_list: function (x)
#> get_available_styles: function ()
#> get_content: function ()
#> get_style: function ()
#> initialize: function (content = character(0), style = private$styles[1])
#> set_content: function (content)
#> set_style: function (style)
#> to_list: function ()
#> Private:
#> content: Some text
#> deep_clone: function (name, value)
#> style: default
#> styles: default header2 header3 verbatim
#>
card$get_metadata()
#> $lm
#>
#> Call:
#> lm(formula = Ozone ~ Solar.R, data = airquality)
#>
#> Coefficients:
#> (Intercept) Solar.R
#> 18.5987 0.1272
#>
#>
library(ggplot2)
card <- ReportCard$new()$append_text("Some text")$append_plot(
ggplot(iris, aes(x = Petal.Length)) + geom_histogram()
)$append_text("Some text")$append_metadata(key = "lm",
value = lm(Ozone ~ Solar.R, airquality))
#> `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
card$get_content()
#> [[1]]
#> <TextBlock>
#> Inherits from: <ContentBlock>
#> Public:
#> clone: function (deep = FALSE)
#> from_list: function (x)
#> get_available_styles: function ()
#> get_content: function ()
#> get_style: function ()
#> initialize: function (content = character(0), style = private$styles[1])
#> set_content: function (content)
#> set_style: function (style)
#> to_list: function ()
#> Private:
#> content: Some text
#> deep_clone: function (name, value)
#> style: default
#> styles: default header2 header3 verbatim
#>
#> [[2]]
#> <PictureBlock>
#> Inherits from: <FileBlock>
#> Public:
#> clone: function (deep = FALSE)
#> from_list: function (x, output_dir)
#> get_content: function ()
#> get_dim: function ()
#> get_title: function ()
#> initialize: function (plot)
#> set_content: function (content)
#> set_dim: function (dim)
#> set_title: function (title)
#> to_list: function (output_dir)
#> Private:
#> content: /tmp/RtmpN84x74/file22223502a8f78.png
#> deep_clone: function (name, value)
#> dim: 800 600
#> finalize: function ()
#> supported_plots: ggplot grob trellis Heatmap
#> title:
#> type:
#>
#> [[3]]
#> <TextBlock>
#> Inherits from: <ContentBlock>
#> Public:
#> clone: function (deep = FALSE)
#> from_list: function (x)
#> get_available_styles: function ()
#> get_content: function ()
#> get_style: function ()
#> initialize: function (content = character(0), style = private$styles[1])
#> set_content: function (content)
#> set_style: function (style)
#> to_list: function ()
#> Private:
#> content: Some text
#> deep_clone: function (name, value)
#> style: default
#> styles: default header2 header3 verbatim
#>
card$to_list(tempdir())
#> $blocks
#> $blocks$TextBlock
#> $blocks$TextBlock$text
#> [1] "Some text"
#>
#> $blocks$TextBlock$style
#> [1] "default"
#>
#>
#> $blocks$PictureBlock
#> $blocks$PictureBlock$basename
#> [1] "file22223502a8f78.png"
#>
#>
#> $blocks$TextBlock
#> $blocks$TextBlock$text
#> [1] "Some text"
#>
#> $blocks$TextBlock$style
#> [1] "default"
#>
#>
#>
#> $metadata
#> $metadata$lm
#>
#> Call:
#> lm(formula = Ozone ~ Solar.R, data = airquality)
#>
#> Coefficients:
#> (Intercept) Solar.R
#> 18.5987 0.1272
#>
#>
#>
#> $name
#> character(0)
#>
library(ggplot2)
card <- ReportCard$new()$append_text("Some text")$append_plot(
ggplot(iris, aes(x = Petal.Length)) + geom_histogram()
)$append_text("Some text")$append_metadata(key = "lm",
value = lm(Ozone ~ Solar.R, airquality))
#> `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
card$get_content()
#> [[1]]
#> <TextBlock>
#> Inherits from: <ContentBlock>
#> Public:
#> clone: function (deep = FALSE)
#> from_list: function (x)
#> get_available_styles: function ()
#> get_content: function ()
#> get_style: function ()
#> initialize: function (content = character(0), style = private$styles[1])
#> set_content: function (content)
#> set_style: function (style)
#> to_list: function ()
#> Private:
#> content: Some text
#> deep_clone: function (name, value)
#> style: default
#> styles: default header2 header3 verbatim
#>
#> [[2]]
#> <PictureBlock>
#> Inherits from: <FileBlock>
#> Public:
#> clone: function (deep = FALSE)
#> from_list: function (x, output_dir)
#> get_content: function ()
#> get_dim: function ()
#> get_title: function ()
#> initialize: function (plot)
#> set_content: function (content)
#> set_dim: function (dim)
#> set_title: function (title)
#> to_list: function (output_dir)
#> Private:
#> content: /tmp/RtmpN84x74/file222237ef1805e.png
#> deep_clone: function (name, value)
#> dim: 800 600
#> finalize: function ()
#> supported_plots: ggplot grob trellis Heatmap
#> title:
#> type:
#>
#> [[3]]
#> <TextBlock>
#> Inherits from: <ContentBlock>
#> Public:
#> clone: function (deep = FALSE)
#> from_list: function (x)
#> get_available_styles: function ()
#> get_content: function ()
#> get_style: function ()
#> initialize: function (content = character(0), style = private$styles[1])
#> set_content: function (content)
#> set_style: function (style)
#> to_list: function ()
#> Private:
#> content: Some text
#> deep_clone: function (name, value)
#> style: default
#> styles: default header2 header3 verbatim
#>
ReportCard$new()$from_list(card$to_list(tempdir()), tempdir())
## ------------------------------------------------
## Method `ReportCard$new`
## ------------------------------------------------
card <- ReportCard$new()
## ------------------------------------------------
## Method `ReportCard$append_table`
## ------------------------------------------------
card <- ReportCard$new()$append_table(iris)
## ------------------------------------------------
## Method `ReportCard$append_html`
## ------------------------------------------------
card <- ReportCard$new()$append_html(shiny::div("HTML Content"))
## ------------------------------------------------
## Method `ReportCard$append_text`
## ------------------------------------------------
card <- ReportCard$new()$append_text("A paragraph of default text")
## ------------------------------------------------
## Method `ReportCard$append_rcode`
## ------------------------------------------------
card <- ReportCard$new()$append_rcode("2+2", echo = FALSE)
## ------------------------------------------------
## Method `ReportCard$append_content`
## ------------------------------------------------
NewpageBlock <- getFromNamespace("NewpageBlock", "teal.reporter")
card <- ReportCard$new()$append_content(NewpageBlock$new())
## ------------------------------------------------
## Method `ReportCard$get_content`
## ------------------------------------------------
card <- ReportCard$new()$append_text("Some text")$append_metadata("rc", "a <- 2 + 2")
card$get_content()
#> [[1]]
#> <TextBlock>
#> Inherits from: <ContentBlock>
#> Public:
#> clone: function (deep = FALSE)
#> from_list: function (x)
#> get_available_styles: function ()
#> get_content: function ()
#> get_style: function ()
#> initialize: function (content = character(0), style = private$styles[1])
#> set_content: function (content)
#> set_style: function (style)
#> to_list: function ()
#> Private:
#> content: Some text
#> deep_clone: function (name, value)
#> style: default
#> styles: default header2 header3 verbatim
#>
## ------------------------------------------------
## Method `ReportCard$get_metadata`
## ------------------------------------------------
card <- ReportCard$new()$append_text("Some text")$append_metadata("rc", "a <- 2 + 2")
card$get_metadata()
#> $rc
#> [1] "a <- 2 + 2"
#>
## ------------------------------------------------
## Method `ReportCard$get_name`
## ------------------------------------------------
ReportCard$new()$set_name("NAME")$get_name()
#> [1] "NAME"
## ------------------------------------------------
## Method `ReportCard$set_name`
## ------------------------------------------------
ReportCard$new()$set_name("NAME")$get_name()
#> [1] "NAME"