Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

* Exported `select_decorators()` to help module developers resolve the decorators applied to a specific output (#1733).

### Bug fixes

* Prevent reporter buttons from appearing in subsequent tabs if functionality is disabled (#1727).

# teal 1.2.1

### Bug fixes
Expand Down
3 changes: 2 additions & 1 deletion R/init.R
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,8 @@ init <- function(data,
),
ui_teal(
id = "teal",
modules = modules
modules = modules,
reporter = reporter
),
tags$footer(
id = "teal-footer",
Expand Down
17 changes: 10 additions & 7 deletions R/module_nested_tabs.R
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,16 @@ NULL


#' @rdname module_teal_module
ui_teal_module <- function(id, modules) {
ui_teal_module <- function(id, modules, reporter) {
ns <- NS(id)
active_module_id <- restoreInput(
ns("active_module_id"),
unlist(modules_slot(modules, "path"), use.names = FALSE)[1]
)

module_items <- .ui_teal_module(id = ns("nav"), modules = modules, active_module_id = active_module_id)
module_items <- .ui_teal_module(
id = ns("nav"), modules = modules, active_module_id = active_module_id, reporter = reporter
)

tags$div(
class = "teal-modules-wrapper",
Expand Down Expand Up @@ -200,25 +202,26 @@ srv_teal_module <- function(id,
}

#' @rdname module_teal_module
.ui_teal_module <- function(id, modules, active_module_id) {
.ui_teal_module <- function(id, modules, active_module_id, reporter) {
checkmate::assert_multi_class(modules, c("teal_modules", "teal_module", "shiny.tag"))
UseMethod(".ui_teal_module", modules)
}

#' @rdname module_teal_module
#' @export
.ui_teal_module.default <- function(id, modules, active_module_id) {
.ui_teal_module.default <- function(id, modules, active_module_id, reporter) {
stop("Modules class not supported: ", paste(class(modules), collapse = " "))
}

#' @rdname module_teal_module
#' @export
.ui_teal_module.teal_modules <- function(id, modules, active_module_id) {
.ui_teal_module.teal_modules <- function(id, modules, active_module_id, reporter) {
items <- mapply(
FUN = .ui_teal_module,
id = NS(id, .label_to_id(sapply(modules$children, `[[`, "label"))),
modules = modules$children,
active_module_id = active_module_id,
MoreArgs = list(reporter = reporter),
SIMPLIFY = FALSE
)

Expand All @@ -233,7 +236,7 @@ srv_teal_module <- function(id,

#' @rdname module_teal_module
#' @export
.ui_teal_module.teal_module <- function(id, modules, active_module_id) {
.ui_teal_module.teal_module <- function(id, modules, active_module_id, reporter) {
ns <- NS(id)
args <- c(list(id = ns("module")), modules$ui_args)
ui_teal <- tags$div(
Expand Down Expand Up @@ -279,7 +282,7 @@ srv_teal_module <- function(id,
.modules_breadcrumb(modules),
tags$div(
style = "display: flex; gap: 0.5em;",
ui_add_reporter(ns("add_reporter_wrapper")),
if (!is.null(reporter)) ui_add_reporter(ns("add_reporter_wrapper")),
ui_source_code(ns("source_code_wrapper"))
)
),
Expand Down
56 changes: 28 additions & 28 deletions R/module_teal.R

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can make small update in vignette teal-as-shiny-module to show the usage of reporter argument for function ui_teal

Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,10 @@ NULL

#' @rdname module_teal
#' @export
ui_teal <- function(id, modules) {
ui_teal <- function(id, modules, reporter = teal.reporter::Reporter$new()) {
checkmate::assert_character(id, max.len = 1, any.missing = FALSE)
checkmate::assert_class(modules, "teal_modules")
checkmate::assert_class(reporter, "Reporter", null.ok = TRUE)
ns <- NS(id)

mod <- extract_module(modules, class = "teal_module_previewer")
Expand All @@ -67,32 +68,34 @@ ui_teal <- function(id, modules) {
)
)

navbar <- ui_teal_module(id = ns("teal_modules"), modules = modules)
navbar <- ui_teal_module(id = ns("teal_modules"), modules = modules, reporter = reporter)
nav_elements <- list(
withr::with_options(reporter_opts, { # for backwards compatibility of the report_previewer_module$server_args
tags$div(
id = ns("reporter_menu_container"),
.teal_navbar_menu(
label = "Report",
icon = "file-text-fill",
class = "reporter-menu",
if ("preview" %in% getOption("teal.reporter.nav_buttons")) {
teal.reporter::preview_report_button_ui(ns("preview_report"), label = "Preview Report")
},
tags$hr(style = "margin: 0.5rem;"),
if ("download" %in% getOption("teal.reporter.nav_buttons")) {
teal.reporter::download_report_button_ui(ns("download_report"), label = "Download Report")
},
if ("load" %in% getOption("teal.reporter.nav_buttons")) {
teal.reporter::report_load_ui(ns("load_report"), label = "Load Report")
},
tags$hr(style = "margin: 0.5rem;"),
if ("reset" %in% getOption("teal.reporter.nav_buttons")) {
teal.reporter::reset_report_button_ui(ns("reset_reports"), label = "Reset Report")
}
if (!is.null(reporter)) {
withr::with_options(reporter_opts, { # for backwards compatibility of the report_previewer_module$server_args

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am surprised withr package is in suggest, it shuold be on imports as it is necessary for the reporter funcionality.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, we can use rlang::with_options which should result in the same outcome

tags$div(
id = ns("reporter_menu_container"),
.teal_navbar_menu(
label = "Report",
icon = "file-text-fill",
class = "reporter-menu",
if ("preview" %in% getOption("teal.reporter.nav_buttons")) {
teal.reporter::preview_report_button_ui(ns("preview_report"), label = "Preview Report")
},
tags$hr(style = "margin: 0.5rem;"),
if ("download" %in% getOption("teal.reporter.nav_buttons")) {
teal.reporter::download_report_button_ui(ns("download_report"), label = "Download Report")
},
if ("load" %in% getOption("teal.reporter.nav_buttons")) {
teal.reporter::report_load_ui(ns("load_report"), label = "Load Report")
},
tags$hr(style = "margin: 0.5rem;"),
if ("reset" %in% getOption("teal.reporter.nav_buttons")) {
teal.reporter::reset_report_button_ui(ns("reset_reports"), label = "Reset Report")
}
)
)
)
}),
})
},
tags$span(style = "margin-left: auto;"),
ui_bookmark_panel(ns("bookmark_manager"), modules),
ui_snapshot_manager_panel(ns("snapshot_manager_panel")),
Expand Down Expand Up @@ -317,9 +320,6 @@ srv_teal <- function(id, data, modules, filter = teal_slices(), reporter = teal.
teal.reporter::report_load_srv("load_report", reporter)
teal.reporter::download_report_button_srv(id = "download_report", reporter = reporter)
teal.reporter::reset_report_button_srv("reset_reports", reporter)
} else {
removeUI(selector = sprintf("#%s", session$ns("reporter_menu_container")))
removeUI(selector = ".report_add_wrapper")
}
}
)
Expand Down
6 changes: 3 additions & 3 deletions man/module_teal.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions man/module_teal_module.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading