From 4a2fc4c378105586cc0191fc074f73c6e8ce2238 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 21 Feb 2024 14:44:33 +0530 Subject: [PATCH 1/4] updating documentation for tm_fron_page --- R/tm_front_page.R | 132 ++++++++++++++++++++++++------------------- man/tm_front_page.Rd | 27 +++++---- 2 files changed, 89 insertions(+), 70 deletions(-) diff --git a/R/tm_front_page.R b/R/tm_front_page.R index aa755d64f..9be6db71d 100644 --- a/R/tm_front_page.R +++ b/R/tm_front_page.R @@ -1,20 +1,21 @@ #' Front page module #' -#' @description This `teal` module creates a simple front page for `teal` applications +#' Creates a simple front page for `teal` applications, displaying +#' introductory text, tables, additional `html` or `shiny` tags, and footnotes. #' #' @inheritParams teal::module -#' @param header_text `character vector` text to be shown at the top of the module, for each -#' element, if named the name is shown first in bold as a header followed by the value. The first -#' element's header is displayed larger than the others -#' @param tables `named list of dataframes` tables to be shown in the module -#' @param additional_tags `shiny.tag.list` or `html` additional shiny tags or `html` to be included after the table, -#' for example to include an image, `tagList(tags$img(src = "image.png"))` or to include further `html`, -#' `HTML("html text here")` -#' @param footnotes `character vector` text to be shown at the bottom of the module, for each -#' element, if named the name is shown first in bold, followed by the value -#' @param show_metadata `logical` should the metadata of the datasets be available on the module? -#' @return A `teal` module to be used in `teal` applications -#' @export +#' @param header_text (`character` vector) text to be shown at the top of the module, for each +#' element, if named the name is shown first in bold as a header followed by the value. The first +#' element's header is displayed larger than the others. +#' @param tables (`named list` of `data.frame`s) tables to be shown in the module. +#' @param additional_tags (`shiny.tag.list` or `html`) additional shiny tags or `html` to be included after the table, +#' for example to include an image, `tagList(tags$img(src = "image.png"))` or to include further `html`, +#' `HTML("html text here")`. +#' @param footnotes (`character` vector) of text to be shown at the bottom of the module, for each +#' element, if named the name is shown first in bold, followed by the value. +#' @param show_metadata (`logical`) indicating whether the metadata of the datasets be available on the module. +#' @return Object of class `teal_module` to be used in `teal` applications. +#' #' @examples #' #' data <- teal_data() @@ -37,9 +38,9 @@ #' "Table 3" = table_3 #' ) #' -#' app <- teal::init( +#' app <- init( #' data = data, -#' modules = teal::modules( +#' modules = modules( #' teal.modules.general::tm_front_page( #' header_text = c( #' "Important information" = "It can go here.", @@ -54,9 +55,13 @@ #' header = tags$h1("Sample Application"), #' footer = tags$p("Application footer"), #' ) +#' #' if (interactive()) { #' shinyApp(app$ui, app$server) #' } +#' +#' @export +#' tm_front_page <- function(label = "Front page", header_text = character(0), tables = list(), @@ -83,6 +88,7 @@ tm_front_page <- function(label = "Front page", ) } +# UI function for the front page module. ui_front_page <- function(id, ...) { args <- list(...) ns <- NS(id) @@ -121,6 +127,53 @@ ui_front_page <- function(id, ...) { ) } +# Server function for the front page module. +srv_front_page <- function(id, data, tables, show_metadata) { + checkmate::assert_class(data, "reactive") + checkmate::assert_class(isolate(data()), "teal_data") + moduleServer(id, function(input, output, session) { + ns <- session$ns + + lapply(seq_along(tables), function(idx) { + output[[paste0("table_", idx)]] <- renderTable( + tables[[idx]], + bordered = TRUE, + caption = names(tables)[idx], + caption.placement = "top" + ) + }) + + if (show_metadata) { + observeEvent( + input$metadata_button, showModal( + modalDialog( + title = "Metadata", + dataTableOutput(ns("metadata_table")), + size = "l", + easyClose = TRUE + ) + ) + ) + + metadata_data_frame <- reactive({ + datanames <- teal.data::datanames(data()) + convert_metadata_to_dataframe( + lapply(datanames, function(dataname) attr(data()[[dataname]], "metadata")), + datanames + ) + }) + + output$metadata_table <- renderDataTable({ + validate(need(nrow(metadata_data_frame()) > 0, "The data has no associated metadata")) + metadata_data_frame() + }) + } + }) +} + +# utils functions +#' @noRd +#' @keywords internal get_header_tags <- function(header_text) { if (length(header_text) == 0) { return(list()) @@ -139,6 +192,8 @@ get_header_tags <- function(header_text) { c(header_tags, mapply(get_single_header_tags, utils::tail(names(header_text), -1), utils::tail(header_text, -1))) } +#' @noRd +#' @keywords internal get_table_tags <- function(tables, ns) { if (length(tables) == 0) { return(list()) @@ -151,6 +206,8 @@ get_table_tags <- function(tables, ns) { return(table_tags) } +#' @noRd +#' @keywords internal get_footer_tags <- function(footnotes) { if (length(footnotes) == 0) { return(list()) @@ -167,52 +224,11 @@ get_footer_tags <- function(footnotes) { }, bold_text = bold_texts, value = footnotes) } -srv_front_page <- function(id, data, tables, show_metadata) { - checkmate::assert_class(data, "reactive") - checkmate::assert_class(isolate(data()), "teal_data") - moduleServer(id, function(input, output, session) { - ns <- session$ns - - lapply(seq_along(tables), function(idx) { - output[[paste0("table_", idx)]] <- renderTable( - tables[[idx]], - bordered = TRUE, - caption = names(tables)[idx], - caption.placement = "top" - ) - }) - - if (show_metadata) { - observeEvent( - input$metadata_button, showModal( - modalDialog( - title = "Metadata", - dataTableOutput(ns("metadata_table")), - size = "l", - easyClose = TRUE - ) - ) - ) - - metadata_data_frame <- reactive({ - datanames <- teal.data::datanames(data()) - convert_metadata_to_dataframe( - lapply(datanames, function(dataname) attr(data()[[dataname]], "metadata")), - datanames - ) - }) - - output$metadata_table <- renderDataTable({ - validate(need(nrow(metadata_data_frame()) > 0, "The data has no associated metadata")) - metadata_data_frame() - }) - } - }) -} - # take a list of metadata, one item per dataset (raw_metadata each element from datasets$get_metadata()) # and the corresponding datanames and output a data.frame with columns {Dataset, Name, Value}. # which are, the Dataset the metadata came from, the metadata's name and value +#' @noRd +#' @keywords internal convert_metadata_to_dataframe <- function(raw_metadata, datanames) { output <- mapply(function(metadata, dataname) { if (is.null(metadata)) { diff --git a/man/tm_front_page.Rd b/man/tm_front_page.Rd index 0efa390d0..97fbf4934 100644 --- a/man/tm_front_page.Rd +++ b/man/tm_front_page.Rd @@ -17,26 +17,27 @@ tm_front_page( \item{label}{(\code{character(1)}) Label shown in the navigation item for the module or module group. For \code{modules()} defaults to \code{"root"}. See \code{Details}.} -\item{header_text}{\verb{character vector} text to be shown at the top of the module, for each +\item{header_text}{(\code{character} vector) text to be shown at the top of the module, for each element, if named the name is shown first in bold as a header followed by the value. The first -element's header is displayed larger than the others} +element's header is displayed larger than the others.} -\item{tables}{\verb{named list of dataframes} tables to be shown in the module} +\item{tables}{(\verb{named list} of \code{data.frame}s) tables to be shown in the module.} -\item{additional_tags}{\code{shiny.tag.list} or \code{html} additional shiny tags or \code{html} to be included after the table, +\item{additional_tags}{(\code{shiny.tag.list} or \code{html}) additional shiny tags or \code{html} to be included after the table, for example to include an image, \code{tagList(tags$img(src = "image.png"))} or to include further \code{html}, -\code{HTML("html text here")}} +\code{HTML("html text here")}.} -\item{footnotes}{\verb{character vector} text to be shown at the bottom of the module, for each -element, if named the name is shown first in bold, followed by the value} +\item{footnotes}{(\code{character} vector) of text to be shown at the bottom of the module, for each +element, if named the name is shown first in bold, followed by the value.} -\item{show_metadata}{\code{logical} should the metadata of the datasets be available on the module?} +\item{show_metadata}{(\code{logical}) indicating whether the metadata of the datasets be available on the module.} } \value{ -A \code{teal} module to be used in \code{teal} applications +Object of class \code{teal_module} to be used in \code{teal} applications. } \description{ -This \code{teal} module creates a simple front page for \code{teal} applications +Creates a simple front page for \code{teal} applications, displaying +introductory text, tables, additional \code{html} or \code{shiny} tags, and footnotes. } \examples{ @@ -60,9 +61,9 @@ table_input <- list( "Table 3" = table_3 ) -app <- teal::init( +app <- init( data = data, - modules = teal::modules( + modules = modules( teal.modules.general::tm_front_page( header_text = c( "Important information" = "It can go here.", @@ -77,7 +78,9 @@ app <- teal::init( header = tags$h1("Sample Application"), footer = tags$p("Application footer"), ) + if (interactive()) { shinyApp(app$ui, app$server) } + } From e7ced827882c8d088ea000106fb157073d9f566a Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 23 Feb 2024 15:18:36 +0530 Subject: [PATCH 2/4] merge back from pre-release --- R/tm_front_page.R | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/R/tm_front_page.R b/R/tm_front_page.R index ad1a936e1..0da37743b 100644 --- a/R/tm_front_page.R +++ b/R/tm_front_page.R @@ -14,7 +14,6 @@ #' @param footnotes (`character` vector) of text to be shown at the bottom of the module, for each #' element, if named the name is shown first in bold, followed by the value. #' @param show_metadata (`logical`) indicating whether the metadata of the datasets be available on the module. -#' @return Object of class `teal_module` to be used in `teal` applications. #' #' @examples #' @@ -89,6 +88,8 @@ tm_front_page <- function(label = "Front page", } # UI function for the front page module. +#' @noRd +#' @keywords internal ui_front_page <- function(id, ...) { args <- list(...) ns <- NS(id) @@ -128,6 +129,8 @@ ui_front_page <- function(id, ...) { } # Server function for the front page module. +#' @noRd +#' @keywords internal srv_front_page <- function(id, data, tables, show_metadata) { checkmate::assert_class(data, "reactive") checkmate::assert_class(isolate(data()), "teal_data") @@ -171,7 +174,8 @@ srv_front_page <- function(id, data, tables, show_metadata) { }) } -# utils functions +## utils functions + #' @noRd #' @keywords internal get_header_tags <- function(header_text) { From 8f5329372b1e0be38389c0c37074740c3fb7583f Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 23 Feb 2024 15:20:12 +0530 Subject: [PATCH 3/4] updating Rd --- man/tm_front_page.Rd | 3 --- 1 file changed, 3 deletions(-) diff --git a/man/tm_front_page.Rd b/man/tm_front_page.Rd index 0649501ee..e8ca98d77 100644 --- a/man/tm_front_page.Rd +++ b/man/tm_front_page.Rd @@ -32,9 +32,6 @@ element, if named the name is shown first in bold, followed by the value.} \item{show_metadata}{(\code{logical}) indicating whether the metadata of the datasets be available on the module.} } -\value{ -Object of class \code{teal_module} to be used in \code{teal} applications. -} \description{ Creates a simple front page for \code{teal} applications, displaying introductory text, tables, additional \code{html} or \code{shiny} tags, and footnotes. From ac94f26a69adafe186e14d8f55af517af605ade4 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 26 Feb 2024 18:45:39 +0530 Subject: [PATCH 4/4] removing tags --- R/tm_front_page.R | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/R/tm_front_page.R b/R/tm_front_page.R index 0da37743b..c10ef2bd0 100644 --- a/R/tm_front_page.R +++ b/R/tm_front_page.R @@ -87,9 +87,7 @@ tm_front_page <- function(label = "Front page", ) } -# UI function for the front page module. -#' @noRd -#' @keywords internal +# UI function for the front page module ui_front_page <- function(id, ...) { args <- list(...) ns <- NS(id) @@ -128,9 +126,7 @@ ui_front_page <- function(id, ...) { ) } -# Server function for the front page module. -#' @noRd -#' @keywords internal +# Server function for the front page module srv_front_page <- function(id, data, tables, show_metadata) { checkmate::assert_class(data, "reactive") checkmate::assert_class(isolate(data()), "teal_data") @@ -176,8 +172,6 @@ srv_front_page <- function(id, data, tables, show_metadata) { ## utils functions -#' @noRd -#' @keywords internal get_header_tags <- function(header_text) { if (length(header_text) == 0) { return(list()) @@ -196,8 +190,6 @@ get_header_tags <- function(header_text) { c(header_tags, mapply(get_single_header_tags, utils::tail(names(header_text), -1), utils::tail(header_text, -1))) } -#' @noRd -#' @keywords internal get_table_tags <- function(tables, ns) { if (length(tables) == 0) { return(list()) @@ -210,8 +202,6 @@ get_table_tags <- function(tables, ns) { return(table_tags) } -#' @noRd -#' @keywords internal get_footer_tags <- function(footnotes) { if (length(footnotes) == 0) { return(list()) @@ -231,8 +221,6 @@ get_footer_tags <- function(footnotes) { # take a list of metadata, one item per dataset (raw_metadata each element from datasets$get_metadata()) # and the corresponding datanames and output a data.frame with columns {Dataset, Name, Value}. # which are, the Dataset the metadata came from, the metadata's name and value -#' @noRd -#' @keywords internal convert_metadata_to_dataframe <- function(raw_metadata, datanames) { output <- mapply(function(metadata, dataname) { if (is.null(metadata)) {