Skip to contents

[Experimental] R6 class that stores and manages report cards.

Note

The function has to be used in the shiny reactive context.

Methods


Method new()

Returns a Reporter object.

Usage

Reporter$new()

Returns

a Reporter object

Examples

reporter <- teal.reporter:::Reporter$new()


Method append_cards()

Appends a table to this Reporter.

Usage

Reporter$append_cards(cards)

Arguments

cards

ReportCard or a list of such objects

Returns

invisibly self

Examples

card1 <- teal.reporter:::ReportCard$new()

card1$append_text("Header 2 text", "header2")
card1$append_text("A paragraph of default text", "header2")
card1$append_plot(
 ggplot2::ggplot(iris, ggplot2::aes(x = Petal.Length)) + ggplot2::geom_histogram()
)

card2 <- teal.reporter:::ReportCard$new()

card2$append_text("Header 2 text", "header2")
card2$append_text("A paragraph of default text", "header2")
lyt <- rtables::analyze(rtables::split_rows_by(rtables::basic_table(), "Day"), "Ozone", afun = mean)
table_res2 <- rtables::build_table(lyt, airquality)
card2$append_table(table_res2)
card2$append_table(iris)

reporter <- teal.reporter:::Reporter$new()
reporter$append_cards(list(card1, card2))


Method get_cards()

Returns cards of this Reporter.

Usage

Reporter$get_cards()

Returns

list() list of ReportCard

Examples

card1 <- teal.reporter:::ReportCard$new()

card1$append_text("Header 2 text", "header2")
card1$append_text("A paragraph of default text", "header2")
card1$append_plot(
 ggplot2::ggplot(iris, ggplot2::aes(x = Petal.Length)) + ggplot2::geom_histogram()
)

card2 <- teal.reporter:::ReportCard$new()

card2$append_text("Header 2 text", "header2")
card2$append_text("A paragraph of default text", "header2")
lyt <- rtables::analyze(rtables::split_rows_by(rtables::basic_table(), "Day"), "Ozone", afun = mean)
table_res2 <- rtables::build_table(lyt, airquality)
card2$append_table(table_res2)
card2$append_table(iris)

reporter <- teal.reporter:::Reporter$new()
reporter$append_cards(list(card1, card2))
reporter$get_cards()


Method get_blocks()

Returns blocks of all ReportCard of this Reporter.

Usage

Reporter$get_blocks(sep = NewpageBlock$new())

Arguments

sep

the element inserted between each content element in this Reporter. Pass NULL to return content without any additional elements. Default: NewpageBlock$new()

Returns

list() list of TableBlock, TextBlock, PictureBlock and NewpageBlock

Examples

card1 <- teal.reporter:::ReportCard$new()

card1$append_text("Header 2 text", "header2")
card1$append_text("A paragraph of default text", "header2")
card1$append_plot(
 ggplot2::ggplot(iris, ggplot2::aes(x = Petal.Length)) + ggplot2::geom_histogram()
)

card2 <- teal.reporter:::ReportCard$new()

card2$append_text("Header 2 text", "header2")
card2$append_text("A paragraph of default text", "header2")
lyt <- rtables::analyze(rtables::split_rows_by(rtables::basic_table(), "Day"), "Ozone", afun = mean)
table_res2 <- rtables::build_table(lyt, airquality)
card2$append_table(table_res2)
card2$append_table(iris)

reporter <- teal.reporter:::Reporter$new()
reporter$append_cards(list(card1, card2))
reporter$get_blocks()


Method reset()

Removes all ReportCard objects added to this Reporter.

Usage

Reporter$reset()

Returns

invisibly self


Method remove_cards()

remove a specific Card in the Reporter

Usage

Reporter$remove_cards(ids = NULL)

Arguments

ids

integer the indexes of cards

Returns

invisibly self


Method swap_cards()

swap two cards in the Reporter

Usage

Reporter$swap_cards(start, end)

Arguments

start

integer the index of the first card

end

integer the index of the second card

Returns

invisibly self


Method get_reactive_add_card()

get a value for the reactive value for the add card

Usage

Reporter$get_reactive_add_card()

Returns

reactive_add_card filed value

Examples

shiny::isolate(Reporter$new()$get_reactive_add_card())


Method clone()

The objects of this class are cloneable with this method.

Usage

Reporter$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.

Examples


## ------------------------------------------------
## Method `Reporter$new`
## ------------------------------------------------

reporter <- teal.reporter:::Reporter$new()


## ------------------------------------------------
## Method `Reporter$append_cards`
## ------------------------------------------------

card1 <- teal.reporter:::ReportCard$new()

card1$append_text("Header 2 text", "header2")
card1$append_text("A paragraph of default text", "header2")
card1$append_plot(
 ggplot2::ggplot(iris, ggplot2::aes(x = Petal.Length)) + ggplot2::geom_histogram()
)
#> `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

card2 <- teal.reporter:::ReportCard$new()

card2$append_text("Header 2 text", "header2")
card2$append_text("A paragraph of default text", "header2")
lyt <- rtables::analyze(rtables::split_rows_by(rtables::basic_table(), "Day"), "Ozone", afun = mean)
table_res2 <- rtables::build_table(lyt, airquality)
#> Split var [Day] was not character or factor. Converting to factor
card2$append_table(table_res2)
card2$append_table(iris)

reporter <- teal.reporter:::Reporter$new()
reporter$append_cards(list(card1, card2))


## ------------------------------------------------
## Method `Reporter$get_cards`
## ------------------------------------------------

card1 <- teal.reporter:::ReportCard$new()

card1$append_text("Header 2 text", "header2")
card1$append_text("A paragraph of default text", "header2")
card1$append_plot(
 ggplot2::ggplot(iris, ggplot2::aes(x = Petal.Length)) + ggplot2::geom_histogram()
)
#> `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

card2 <- teal.reporter:::ReportCard$new()

card2$append_text("Header 2 text", "header2")
card2$append_text("A paragraph of default text", "header2")
lyt <- rtables::analyze(rtables::split_rows_by(rtables::basic_table(), "Day"), "Ozone", afun = mean)
table_res2 <- rtables::build_table(lyt, airquality)
#> Split var [Day] was not character or factor. Converting to factor
card2$append_table(table_res2)
card2$append_table(iris)

reporter <- teal.reporter:::Reporter$new()
reporter$append_cards(list(card1, card2))
reporter$get_cards()
#> [[1]]
#> <ReportCard>
#>   Public:
#>     append_metadata: function (key, value) 
#>     append_plot: function (plot) 
#>     append_table: function (table) 
#>     append_text: function (text, style = TextBlock$new()$get_available_styles()[1]) 
#>     clone: function (deep = FALSE) 
#>     get_content: function () 
#>     get_metadata: function () 
#>     get_name: function () 
#>     initialize: function () 
#>     set_name: function (name) 
#>   Private:
#>     content: list
#>     deep_clone: function (name, value) 
#>     metadata: list
#>     name: 
#> 
#> [[2]]
#> <ReportCard>
#>   Public:
#>     append_metadata: function (key, value) 
#>     append_plot: function (plot) 
#>     append_table: function (table) 
#>     append_text: function (text, style = TextBlock$new()$get_available_styles()[1]) 
#>     clone: function (deep = FALSE) 
#>     get_content: function () 
#>     get_metadata: function () 
#>     get_name: function () 
#>     initialize: function () 
#>     set_name: function (name) 
#>   Private:
#>     content: list
#>     deep_clone: function (name, value) 
#>     metadata: list
#>     name: 
#> 

## ------------------------------------------------
## Method `Reporter$get_blocks`
## ------------------------------------------------

card1 <- teal.reporter:::ReportCard$new()

card1$append_text("Header 2 text", "header2")
card1$append_text("A paragraph of default text", "header2")
card1$append_plot(
 ggplot2::ggplot(iris, ggplot2::aes(x = Petal.Length)) + ggplot2::geom_histogram()
)
#> `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

card2 <- teal.reporter:::ReportCard$new()

card2$append_text("Header 2 text", "header2")
card2$append_text("A paragraph of default text", "header2")
lyt <- rtables::analyze(rtables::split_rows_by(rtables::basic_table(), "Day"), "Ozone", afun = mean)
table_res2 <- rtables::build_table(lyt, airquality)
#> Split var [Day] was not character or factor. Converting to factor
card2$append_table(table_res2)
card2$append_table(iris)

reporter <- teal.reporter:::Reporter$new()
reporter$append_cards(list(card1, card2))
reporter$get_blocks()
#> [[1]]
#> <TextBlock>
#>   Inherits from: <ContentBlock>
#>   Public:
#>     clone: function (deep = FALSE) 
#>     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) 
#>   Private:
#>     content: Header 2 text
#>     deep_clone: function (name, value) 
#>     style: header2
#>     styles: default header2 header3 verbatim
#> 
#> [[2]]
#> <TextBlock>
#>   Inherits from: <ContentBlock>
#>   Public:
#>     clone: function (deep = FALSE) 
#>     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) 
#>   Private:
#>     content: A paragraph of default text
#>     deep_clone: function (name, value) 
#>     style: header2
#>     styles: default header2 header3 verbatim
#> 
#> [[3]]
#> <PictureBlock>
#>   Inherits from: <ContentBlock>
#>   Public:
#>     clone: function (deep = FALSE) 
#>     finalize: function () 
#>     get_content: function () 
#>     get_dim: function () 
#>     get_title: function () 
#>     initialize: function (plot) 
#>     set_content: function (content) 
#>     set_dim: function (dim) 
#>     set_title: function (title) 
#>   Private:
#>     content: /tmp/Rtmp1ipjwB/file19fc7db568.png
#>     deep_clone: function (name, value) 
#>     dim: 800 600
#>     supported_plots: ggplot grob trellis
#>     title: 
#>     type: 
#> 
#> [[4]]
#> <NewpageBlock>
#>   Inherits from: <ContentBlock>
#>   Public:
#>     clone: function (deep = FALSE) 
#>     get_content: function () 
#>     initialize: function () 
#>     set_content: function (content) 
#>   Private:
#>     content: 
#>     \newpage
#> 
#>     deep_clone: function (name, value) 
#> 
#> [[5]]
#> <TextBlock>
#>   Inherits from: <ContentBlock>
#>   Public:
#>     clone: function (deep = FALSE) 
#>     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) 
#>   Private:
#>     content: Header 2 text
#>     deep_clone: function (name, value) 
#>     style: header2
#>     styles: default header2 header3 verbatim
#> 
#> [[6]]
#> <TextBlock>
#>   Inherits from: <ContentBlock>
#>   Public:
#>     clone: function (deep = FALSE) 
#>     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) 
#>   Private:
#>     content: A paragraph of default text
#>     deep_clone: function (name, value) 
#>     style: header2
#>     styles: default header2 header3 verbatim
#> 
#> [[7]]
#> <TableBlock>
#>   Inherits from: <ContentBlock>
#>   Public:
#>     clone: function (deep = FALSE) 
#>     finalize: function () 
#>     get_content: function () 
#>     initialize: function (table) 
#>     set_content: function (content) 
#>   Private:
#>     content: /tmp/Rtmp1ipjwB/file19f4592174b.rds
#>     deep_clone: function (name, value) 
#>     supported_tables: data.frame rtables TableTree
#> 
#> [[8]]
#> <TableBlock>
#>   Inherits from: <ContentBlock>
#>   Public:
#>     clone: function (deep = FALSE) 
#>     finalize: function () 
#>     get_content: function () 
#>     initialize: function (table) 
#>     set_content: function (content) 
#>   Private:
#>     content: /tmp/Rtmp1ipjwB/file19f4538c696.rds
#>     deep_clone: function (name, value) 
#>     supported_tables: data.frame rtables TableTree
#> 


## ------------------------------------------------
## Method `Reporter$get_reactive_add_card`
## ------------------------------------------------

shiny::isolate(Reporter$new()$get_reactive_add_card())
#> [1] 0