Reporter | R Documentation |
Reporter
: An R6
class for managing report cardsThis R6
class is designed to store and manage report cards,
facilitating the creation, manipulation, and serialization of report-related data.
new()
Initialize a Reporter
object.
Reporter$new()
Object of class Reporter
, invisibly.
reporter <- Reporter$new()
append_cards()
Append one or more ReportCard
objects to the Reporter
.
Reporter$append_cards(cards)
cards
(ReportCard
) or a list of such objects
self
, invisibly.
get_cards()
Retrieves all ReportCard
objects contained in the Reporter
.
Reporter$get_cards()
A (list
) of ReportCard
objects.
get_blocks()
Compiles and returns all content blocks from the ReportCard
in the Reporter
.
Reporter$get_blocks(sep = NewpageBlock$new())
sep
An optional separator to insert between each content block.
Default is a NewpageBlock$new()
object.
list()
list of TableBlock
, TextBlock
, PictureBlock
and NewpageBlock
.
reset()
Resets the Reporter
, removing all ReportCard
objects and metadata.
Reporter$reset()
self
, invisibly.
remove_cards()
Removes specific ReportCard
objects from the Reporter
by their indices.
Reporter$remove_cards(ids = NULL)
ids
(integer(id)
) the indexes of cards
self
, invisibly.
swap_cards()
Swaps the positions of two ReportCard
objects within the Reporter
.
Reporter$swap_cards(start, end)
start
(integer
) the index of the first card
end
(integer
) the index of the second card
self
, invisibly.
get_reactive_add_card()
Gets the current value of the reactive variable for adding cards.
Reporter$get_reactive_add_card()
reactive_add_card
current numeric
value of the reactive variable.
library(shiny) isolate(Reporter$new()$get_reactive_add_card())
get_metadata()
Get the metadata associated with this Reporter
.
Reporter$get_metadata()
named list
of metadata to be appended.
reporter <- Reporter$new()$append_metadata(list(sth = "sth")) reporter$get_metadata()
append_metadata()
Appends metadata to this Reporter
.
Reporter$append_metadata(meta)
meta
(named list
) of metadata to be appended.
self
, invisibly.
reporter <- Reporter$new()$append_metadata(list(sth = "sth")) reporter$get_metadata()
from_reporter()
Reinitializes a Reporter
instance by copying the report cards and metadata from another Reporter
.
Reporter$from_reporter(reporter)
reporter
(Reporter
) instance to copy from.
invisibly self
reporter <- Reporter$new() reporter$from_reporter(reporter)
to_list()
Convert a Reporter
to a list and transfer any associated files to specified directory.
Reporter$to_list(output_dir)
output_dir
(character(1)
) a path to the directory where files will be copied.
named list
representing the Reporter
instance, including version information,
metadata, and report cards.
reporter <- Reporter$new() tmp_dir <- file.path(tempdir(), "testdir") dir.create(tmp_dir) reporter$to_list(tmp_dir)
from_list()
Reinitializes a Reporter
from a list representation and associated files in a specified directory.
Reporter$from_list(rlist, output_dir)
rlist
(named list
) representing a Reporter
instance.
output_dir
(character(1)
) a path to the directory from which files will be copied.
self
, invisibly.
reporter <- Reporter$new() tmp_dir <- file.path(tempdir(), "testdir") unlink(tmp_dir, recursive = TRUE) dir.create(tmp_dir) reporter$from_list(reporter$to_list(tmp_dir), tmp_dir)
to_jsondir()
Serializes the Reporter
to a JSON
file and copies any associated files to a specified directory.
Reporter$to_jsondir(output_dir)
output_dir
(character(1)
) a path to the directory where files will be copied, JSON
and statics.
output_dir
argument.
reporter <- Reporter$new() tmp_dir <- file.path(tempdir(), "jsondir") dir.create(tmp_dir) reporter$to_jsondir(tmp_dir)
from_jsondir()
Reinitializes a Reporter
from a JSON
file and files in a specified directory.
Reporter$from_jsondir(output_dir)
output_dir
(character(1)
) a path to the directory with files, JSON
and statics.
self
, invisibly.
reporter <- Reporter$new() tmp_dir <- file.path(tempdir(), "jsondir") dir.create(tmp_dir) unlink(list.files(tmp_dir, recursive = TRUE)) reporter$to_jsondir(tmp_dir) reporter$from_jsondir(tmp_dir)
set_id()
Set the Reporter
id
Optionally add id to a Reporter
which will be compared when it is rebuilt from a list.
The id is added to the downloaded file name.
Reporter$set_id(id)
id
(character(1)
) a Report id.
self
, invisibly.
get_id()
Get the Reporter
id
Reporter$get_id()
character(1)
the Reporter
id.
clone()
The objects of this class are cloneable with this method.
Reporter$clone(deep = FALSE)
deep
Whether to make a deep clone.
The function has to be used in the shiny reactive context.
if Report has an id when converting to JSON then It will be compared to the currently available one.
if Report has an id when converting to JSON then It will be compared to the currently available one.
library(ggplot2)
library(rtables)
card1 <- ReportCard$new()
card1$append_text("Header 2 text", "header2")
card1$append_text("A paragraph of default text")
card1$append_plot(
ggplot(iris, aes(x = Petal.Length)) + geom_histogram()
)
card2 <- ReportCard$new()
card2$append_text("Header 2 text", "header2")
card2$append_text("A paragraph of default text")
lyt <- analyze(split_rows_by(basic_table(), "Day"), "Ozone", afun = mean)
table_res2 <- build_table(lyt, airquality)
card2$append_table(table_res2)
reporter <- Reporter$new()
reporter$append_cards(list(card1, card2))
library(ggplot2)
library(rtables)
card1 <- ReportCard$new()
card1$append_text("Header 2 text", "header2")
card1$append_text("A paragraph of default text")
card1$append_plot(
ggplot(iris, aes(x = Petal.Length)) + geom_histogram()
)
card2 <- ReportCard$new()
card2$append_text("Header 2 text", "header2")
card2$append_text("A paragraph of default text")
lyt <- analyze(split_rows_by(basic_table(), "Day"), "Ozone", afun = mean)
table_res2 <- build_table(lyt, airquality)
card2$append_table(table_res2)
reporter <- Reporter$new()
reporter$append_cards(list(card1, card2))
reporter$get_cards()
library(ggplot2)
library(rtables)
card1 <- ReportCard$new()
card1$append_text("Header 2 text", "header2")
card1$append_text("A paragraph of default text")
card1$append_plot(
ggplot(iris, aes(x = Petal.Length)) + geom_histogram()
)
card2 <- ReportCard$new()
card2$append_text("Header 2 text", "header2")
card2$append_text("A paragraph of default text")
lyt <- analyze(split_rows_by(basic_table(), "Day"), "Ozone", afun = mean)
table_res2 <- build_table(lyt, airquality)
card2$append_table(table_res2)
reporter <- Reporter$new()
reporter$append_cards(list(card1, card2))
reporter$get_blocks()
## ------------------------------------------------
## Method `Reporter$new`
## ------------------------------------------------
reporter <- Reporter$new()
## ------------------------------------------------
## Method `Reporter$get_reactive_add_card`
## ------------------------------------------------
library(shiny)
isolate(Reporter$new()$get_reactive_add_card())
## ------------------------------------------------
## Method `Reporter$get_metadata`
## ------------------------------------------------
reporter <- Reporter$new()$append_metadata(list(sth = "sth"))
reporter$get_metadata()
## ------------------------------------------------
## Method `Reporter$append_metadata`
## ------------------------------------------------
reporter <- Reporter$new()$append_metadata(list(sth = "sth"))
reporter$get_metadata()
## ------------------------------------------------
## Method `Reporter$from_reporter`
## ------------------------------------------------
reporter <- Reporter$new()
reporter$from_reporter(reporter)
## ------------------------------------------------
## Method `Reporter$to_list`
## ------------------------------------------------
reporter <- Reporter$new()
tmp_dir <- file.path(tempdir(), "testdir")
dir.create(tmp_dir)
reporter$to_list(tmp_dir)
## ------------------------------------------------
## Method `Reporter$from_list`
## ------------------------------------------------
reporter <- Reporter$new()
tmp_dir <- file.path(tempdir(), "testdir")
unlink(tmp_dir, recursive = TRUE)
dir.create(tmp_dir)
reporter$from_list(reporter$to_list(tmp_dir), tmp_dir)
## ------------------------------------------------
## Method `Reporter$to_jsondir`
## ------------------------------------------------
reporter <- Reporter$new()
tmp_dir <- file.path(tempdir(), "jsondir")
dir.create(tmp_dir)
reporter$to_jsondir(tmp_dir)
## ------------------------------------------------
## Method `Reporter$from_jsondir`
## ------------------------------------------------
reporter <- Reporter$new()
tmp_dir <- file.path(tempdir(), "jsondir")
dir.create(tmp_dir)
unlink(list.files(tmp_dir, recursive = TRUE))
reporter$to_jsondir(tmp_dir)
reporter$from_jsondir(tmp_dir)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.