Title: | Reporting Tools for 'shiny' Modules |
---|---|
Description: | Prebuilt 'shiny' modules containing tools for the generation of 'rmarkdown' reports, supporting reproducible research and analysis. |
Authors: | Dawid Kaledkowski [aut, cre] , Kartikeya Kirar [aut] , Marcin Kosinski [aut], Maciej Nasinski [aut], Konrad Pagacz [aut], Mahmoud Hallal [aut], Chendi Liao [rev], Dony Unardi [rev], F. Hoffmann-La Roche AG [cph, fnd] |
Maintainer: | Dawid Kaledkowski <[email protected]> |
License: | Apache License 2.0 |
Version: | 0.3.1.9016 |
Built: | 2024-11-15 05:53:49 UTC |
Source: | https://github.com/insightsengineering/teal.reporter |
Provides a button to add views/cards to a report.
For more details see the vignette: vignette("simpleReporter", "teal.reporter")
.
add_card_button_ui(id) add_card_button_srv(id, reporter, card_fun)
add_card_button_ui(id) add_card_button_srv(id, reporter, card_fun)
id |
( |
reporter |
( |
card_fun |
( |
The card_fun
function is designed to create a new ReportCard
instance and optionally customize it:
The card
parameter allows for specifying a custom or default ReportCard
instance.
Use the comment
parameter to add a comment to the card via card$append_text()
- if card_fun
does not
have the comment
parameter, then comment
from Add Card UI
module will be added at the end of the content of the
card.
The label
parameter enables customization of the card's name and its content through card$append_text()
-
if card_fun
does not have the label
parameter, then card name will be set to the name passed in
Add Card UI
module, but no text will be added to the content of the card
.
This module supports using a subclass of ReportCard
for added flexibility.
A subclass instance should be passed as the default value of
the card
argument in the card_fun
function.
See below:
CustomReportCard <- R6::R6Class( classname = "CustomReportCard", inherit = teal.reporter::ReportCard ) custom_function <- function(card = CustomReportCard$new()) { card }
NULL
.
yaml
header for an Rmd
fileConverts a named list into a yaml
header for Rmd
, handling output types and arguments
as defined in the rmarkdown
package. This function simplifies the process of generating yaml
headers.
as_yaml_auto( input_list, as_header = TRUE, convert_logi = TRUE, multi_output = FALSE, silent = FALSE )
as_yaml_auto( input_list, as_header = TRUE, convert_logi = TRUE, multi_output = FALSE, silent = FALSE )
input_list |
( |
as_header |
( |
convert_logi |
( |
multi_output |
( |
silent |
( |
This function processes a non-nested (flat) named list into a yaml
header for an Rmd
document.
It supports all standard Rmd
yaml
header fields, including author
, date
, title
, subtitle
,
abstract
, keywords
, subject
, description
, category
, and lang
.
Additionally, it handles output
field types and arguments as defined in the rmarkdown
package.
character
with rmd_yaml_header
class,
result of yaml::as.yaml
, optionally wrapped with internal md_header()
.
Only non-nested lists are automatically parsed.
Nested lists require direct processing with yaml::as.yaml
.
# nested so using yaml::as.yaml directly as_yaml_auto( list(author = "", output = list(pdf_document = list(toc = TRUE))) ) # auto parsing for a flat list, like shiny input input <- list(author = "", output = "pdf_document", toc = TRUE, keep_tex = TRUE) as_yaml_auto(input) as_yaml_auto(list(author = "", output = "pdf_document", toc = TRUE, keep_tex = "TRUE")) as_yaml_auto(list( author = "", output = "pdf_document", toc = TRUE, keep_tex = TRUE, wrong = 2 )) as_yaml_auto(list(author = "", output = "pdf_document", toc = TRUE, keep_tex = 2), silent = TRUE ) input <- list(author = "", output = "pdf_document", toc = TRUE, keep_tex = "True") as_yaml_auto(input) as_yaml_auto(input, convert_logi = TRUE, silent = TRUE) as_yaml_auto(input, silent = TRUE) as_yaml_auto(input, convert_logi = FALSE, silent = TRUE) as_yaml_auto( list( author = "", output = "pdf_document", output = "html_document", toc = TRUE, keep_tex = TRUE ), multi_output = TRUE ) as_yaml_auto( list( author = "", output = "pdf_document", output = "html_document", toc = "True", keep_tex = TRUE ), multi_output = TRUE )
# nested so using yaml::as.yaml directly as_yaml_auto( list(author = "", output = list(pdf_document = list(toc = TRUE))) ) # auto parsing for a flat list, like shiny input input <- list(author = "", output = "pdf_document", toc = TRUE, keep_tex = TRUE) as_yaml_auto(input) as_yaml_auto(list(author = "", output = "pdf_document", toc = TRUE, keep_tex = "TRUE")) as_yaml_auto(list( author = "", output = "pdf_document", toc = TRUE, keep_tex = TRUE, wrong = 2 )) as_yaml_auto(list(author = "", output = "pdf_document", toc = TRUE, keep_tex = 2), silent = TRUE ) input <- list(author = "", output = "pdf_document", toc = TRUE, keep_tex = "True") as_yaml_auto(input) as_yaml_auto(input, convert_logi = TRUE, silent = TRUE) as_yaml_auto(input, silent = TRUE) as_yaml_auto(input, convert_logi = FALSE, silent = TRUE) as_yaml_auto( list( author = "", output = "pdf_document", output = "html_document", toc = TRUE, keep_tex = TRUE ), multi_output = TRUE ) as_yaml_auto( list( author = "", output = "pdf_document", output = "html_document", toc = "True", keep_tex = TRUE ), multi_output = TRUE )
Provides a button that triggers downloading a report.
For more information, refer to the vignette: vignette("simpleReporter", "teal.reporter")
.
download_report_button_ui(id) download_report_button_srv( id, reporter, global_knitr = getOption("teal.reporter.global_knitr"), rmd_output = c(html = "html_document", pdf = "pdf_document", powerpoint = "powerpoint_presentation", word = "word_document"), rmd_yaml_args = list(author = "NEST", title = "Report", date = as.character(Sys.Date()), output = "html_document", toc = FALSE) )
download_report_button_ui(id) download_report_button_srv( id, reporter, global_knitr = getOption("teal.reporter.global_knitr"), rmd_output = c(html = "html_document", pdf = "pdf_document", powerpoint = "powerpoint_presentation", word = "word_document"), rmd_yaml_args = list(author = "NEST", title = "Report", date = as.character(Sys.Date()), output = "html_document", toc = FALSE) )
id |
( |
reporter |
( |
global_knitr |
( |
rmd_output |
( |
rmd_yaml_args |
( |
To access the default values for the global_knitr
parameter,
use getOption('teal.reporter.global_knitr')
. These defaults include:
echo = TRUE
tidy.opts = list(width.cutoff = 60)
tidy = TRUE
if formatR
package is installed, FALSE
otherwise
NULL
.
yaml_header
class## S3 method for class 'rmd_yaml_header' print(x, ...)
## S3 method for class 'rmd_yaml_header' print(x, ...)
x |
( |
... |
optional text. |
NULL
.
input <- list(author = "", output = "pdf_document", toc = TRUE, keep_tex = TRUE) out <- as_yaml_auto(input) out print(out)
input <- list(author = "", output = "pdf_document", toc = TRUE, keep_tex = TRUE) out <- as_yaml_auto(input) out print(out)
Reporter
Server to load ReporterCard
(s) to the Reporter
For more details see the vignette: vignette("simpleReporter", "teal.reporter")
.
report_load_srv(id, reporter)
report_load_srv(id, reporter)
id |
|
reporter |
|
shiny::moduleServer
Reporter
Button to upload ReporterCard
(s) to the Reporter
.
For more details see the vignette: vignette("simpleReporter", "teal.reporter")
.
report_load_ui(id)
report_load_ui(id)
id |
|
shiny::tagList
ReportCard
: An R6
class for building report elementsThis 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()
Object of class ReportCard
, invisibly.
card <- ReportCard$new()
append_table()
Appends a table to this ReportCard
.
ReportCard$append_table(table)
table
A (data.frame
or rtables
or TableTree
or ElementaryTable
or listing_df
)
that can be coerced into a table.
self
, invisibly.
card <- ReportCard$new()$append_table(iris)
append_plot()
Appends a plot to this ReportCard
.
ReportCard$append_plot(plot, dim = NULL)
plot
(ggplot
or grob
or trellis
) plot object.
dim
(numeric(2)
) width and height in pixels.
self
, invisibly.
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
, header
, verbatim
self
, invisibly.
card <- ReportCard$new()$append_text("A paragraph of default text")
append_rcode()
Appends an R
code chunk to ReportCard
.
ReportCard$append_rcode(text, ...)
text
(character
) The R
code to include.
...
Additional rmarkdown
parameters for formatting the R
code chunk.
self
, invisibly.
card <- ReportCard$new()$append_rcode("2+2", echo = FALSE)
append_content()
Appends a generic ContentBlock
to this ReportCard
.
ReportCard$append_content(content)
content
(ContentBlock
) object.
self
, invisibly.
NewpageBlock <- getFromNamespace("NewpageBlock", "teal.reporter") card <- ReportCard$new()$append_content(NewpageBlock$new())
get_content()
Get all content blocks from this ReportCard
.
ReportCard$get_content()
list()
list of TableBlock
, TextBlock
and PictureBlock
.
card <- ReportCard$new()$append_text("Some text")$append_metadata("rc", "a <- 2 + 2") card$get_content()
reset()
Clears all content and metadata from ReportCard
.
ReportCard$reset()
self
, invisibly.
get_metadata()
Get the metadata associated with ReportCard
.
ReportCard$get_metadata()
named list
list of elements.
card <- ReportCard$new()$append_text("Some text")$append_metadata("rc", "a <- 2 + 2") card$get_metadata()
append_metadata()
Appends metadata to this ReportCard
.
ReportCard$append_metadata(key, value)
key
(character(1)
) string specifying the metadata key.
value
value associated with the metadata key.
self
, invisibly.
get_name()
Get the name of the ReportCard
.
ReportCard$get_name()
character
a card name.
ReportCard$new()$set_name("NAME")$get_name()
set_name()
Set the name of the ReportCard
.
ReportCard$set_name(name)
name
(character(1)
) a card name.
self
, invisibly.
ReportCard$new()$set_name("NAME")$get_name()
to_list()
Convert the ReportCard
to a list, including content and metadata.
ReportCard$to_list(output_dir)
output_dir
(character
) with a path to the directory where files will be copied.
(named list
) a ReportCard
representation.
from_list()
Reconstructs the ReportCard
from a list representation.
ReportCard$from_list(card, output_dir)
card
(named list
) a ReportCard
representation.
output_dir
(character
) with a path to the directory where a file will be copied.
self
, invisibly.
clone()
The objects of this class are cloneable with this method.
ReportCard$clone(deep = FALSE)
deep
Whether to make a deep clone.
library(ggplot2) card <- ReportCard$new()$append_plot( ggplot(iris, aes(x = Petal.Length)) + geom_histogram() ) 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)) card$get_content() card$get_metadata() 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)) card$get_content() card$to_list(tempdir()) 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)) card$get_content() 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_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() ## ------------------------------------------------ ## Method `ReportCard$get_metadata` ## ------------------------------------------------ card <- ReportCard$new()$append_text("Some text")$append_metadata("rc", "a <- 2 + 2") card$get_metadata() ## ------------------------------------------------ ## Method `ReportCard$get_name` ## ------------------------------------------------ ReportCard$new()$set_name("NAME")$get_name() ## ------------------------------------------------ ## Method `ReportCard$set_name` ## ------------------------------------------------ ReportCard$new()$set_name("NAME")$get_name()
library(ggplot2) card <- ReportCard$new()$append_plot( ggplot(iris, aes(x = Petal.Length)) + geom_histogram() ) 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)) card$get_content() card$get_metadata() 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)) card$get_content() card$to_list(tempdir()) 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)) card$get_content() 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_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() ## ------------------------------------------------ ## Method `ReportCard$get_metadata` ## ------------------------------------------------ card <- ReportCard$new()$append_text("Some text")$append_metadata("rc", "a <- 2 + 2") card$get_metadata() ## ------------------------------------------------ ## Method `ReportCard$get_name` ## ------------------------------------------------ ReportCard$new()$set_name("NAME")$get_name() ## ------------------------------------------------ ## Method `ReportCard$set_name` ## ------------------------------------------------ ReportCard$new()$set_name("NAME")$get_name()
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", "header2") 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", "header2") lyt <- analyze(split_rows_by(basic_table(), "Day"), "Ozone", afun = mean) table_res2 <- build_table(lyt, airquality) card2$append_table(table_res2) card2$append_table(iris) 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", "header2") 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", "header2") lyt <- analyze(split_rows_by(basic_table(), "Day"), "Ozone", afun = mean) table_res2 <- build_table(lyt, airquality) card2$append_table(table_res2) card2$append_table(iris) 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", "header2") 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", "header2") lyt <- analyze(split_rows_by(basic_table(), "Day"), "Ozone", afun = mean) table_res2 <- build_table(lyt, airquality) card2$append_table(table_res2) card2$append_table(iris) 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)
library(ggplot2) library(rtables) card1 <- ReportCard$new() card1$append_text("Header 2 text", "header2") card1$append_text("A paragraph of default text", "header2") 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", "header2") lyt <- analyze(split_rows_by(basic_table(), "Day"), "Ozone", afun = mean) table_res2 <- build_table(lyt, airquality) card2$append_table(table_res2) card2$append_table(iris) 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", "header2") 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", "header2") lyt <- analyze(split_rows_by(basic_table(), "Day"), "Ozone", afun = mean) table_res2 <- build_table(lyt, airquality) card2$append_table(table_res2) card2$append_table(iris) 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", "header2") 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", "header2") lyt <- analyze(split_rows_by(basic_table(), "Day"), "Ozone", afun = mean) table_res2 <- build_table(lyt, airquality) card2$append_table(table_res2) card2$append_table(iris) 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)
Module offers functionalities to visualize, manipulate, and interact with report cards that have been added to a report. It includes a previewer interface to see the cards and options to modify the report before downloading.
Cards are saved by the shiny
bookmarking mechanism.
For more details see the vignette: vignette("previewerReporter", "teal.reporter")
.
reporter_previewer_ui(id) reporter_previewer_srv( id, reporter, global_knitr = getOption("teal.reporter.global_knitr"), rmd_output = c(html = "html_document", pdf = "pdf_document", powerpoint = "powerpoint_presentation", word = "word_document"), rmd_yaml_args = list(author = "NEST", title = "Report", date = as.character(Sys.Date()), output = "html_document", toc = FALSE), previewer_buttons = c("download", "load", "reset") )
reporter_previewer_ui(id) reporter_previewer_srv( id, reporter, global_knitr = getOption("teal.reporter.global_knitr"), rmd_output = c(html = "html_document", pdf = "pdf_document", powerpoint = "powerpoint_presentation", word = "word_document"), rmd_yaml_args = list(author = "NEST", title = "Report", date = as.character(Sys.Date()), output = "html_document", toc = FALSE), previewer_buttons = c("download", "load", "reset") )
id |
( |
reporter |
( |
global_knitr |
( |
rmd_output |
( |
rmd_yaml_args |
( |
previewer_buttons |
( |
To access the default values for the global_knitr
parameter,
use getOption('teal.reporter.global_knitr')
. These defaults include:
echo = TRUE
tidy.opts = list(width.cutoff = 60)
tidy = TRUE
if formatR
package is installed, FALSE
otherwise
NULL
.
Provides a button that triggers resetting the report content.
For more information, refer to the vignette: vignette("simpleReporter", "teal.reporter")
.
reset_report_button_ui(id, label = NULL) reset_report_button_srv(id, reporter)
reset_report_button_ui(id, label = NULL) reset_report_button_srv(id, reporter)
id |
( |
label |
( |
reporter |
( |
NULL
.
rmarkdown
packageRetrieves the arguments for a specified document output type from the rmarkdown
package.
rmd_output_arguments(output_name, default_values = FALSE)
rmd_output_arguments(output_name, default_values = FALSE)
output_name |
( |
default_values |
( |
rmd_output_arguments("pdf_document") rmd_output_arguments("pdf_document", TRUE)
rmd_output_arguments("pdf_document") rmd_output_arguments("pdf_document", TRUE)
rmarkdown
packageRetrieves vector of available document output types from the rmarkdown
package,
such as pdf_document
, html_document
, etc.
rmd_outputs()
rmd_outputs()
character
vector.
rmd_outputs()
rmd_outputs()
Module provides compact UI and server functions for managing a report in a shiny
app.
This module combines functionalities for adding cards to a report,
downloading the report, and resetting report content.
For more details see the vignette: vignette("simpleReporter", "teal.reporter")
.
simple_reporter_ui(id) simple_reporter_srv( id, reporter, card_fun, global_knitr = getOption("teal.reporter.global_knitr"), rmd_output = c(html = "html_document", pdf = "pdf_document", powerpoint = "powerpoint_presentation", word = "word_document"), rmd_yaml_args = list(author = "NEST", title = "Report", date = as.character(Sys.Date()), output = "html_document", toc = FALSE) )
simple_reporter_ui(id) simple_reporter_srv( id, reporter, card_fun, global_knitr = getOption("teal.reporter.global_knitr"), rmd_output = c(html = "html_document", pdf = "pdf_document", powerpoint = "powerpoint_presentation", word = "word_document"), rmd_yaml_args = list(author = "NEST", title = "Report", date = as.character(Sys.Date()), output = "html_document", toc = FALSE) )
id |
( |
reporter |
( |
card_fun |
( |
global_knitr |
( |
rmd_output |
( |
rmd_yaml_args |
( |
To access the default values for the global_knitr
parameter,
use getOption('teal.reporter.global_knitr')
. These defaults include:
echo = TRUE
tidy.opts = list(width.cutoff = 60)
tidy = TRUE
if formatR
package is installed, FALSE
otherwise
NULL
.
if (interactive()) { library(shiny) shinyApp( ui = fluidPage(simple_reporter_ui("simple")), server = function(input, output, session) { simple_reporter_srv("simple", Reporter$new(), function(card) card) } ) }
if (interactive()) { library(shiny) shinyApp( ui = fluidPage(simple_reporter_ui("simple")), server = function(input, output, session) { simple_reporter_srv("simple", Reporter$new(), function(card) card) } ) }