From 96babbadaf02f566dac1906cf208eae4a1b72d49 Mon Sep 17 00:00:00 2001 From: m7pr Date: Wed, 30 Aug 2023 12:57:10 +0200 Subject: [PATCH 01/19] #51 unify page version to /latest-tag/ --- .github/CONTRIBUTING.md | 6 +++--- .github/ISSUE_TEMPLATE/bug.yml | 4 ++-- .github/ISSUE_TEMPLATE/feature.yml | 4 ++-- .github/ISSUE_TEMPLATE/question.yml | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index 278c2c65..fb095c4f 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -130,7 +130,7 @@ The package maintainer also reserves the right to adjust the criteria to recogni If you have further questions regarding the contribution guidelines, please contact the package/repository maintainer. -[docs]: https://insightsengineering.github.io/teal.logger/index.html -[articles]: https://insightsengineering.github.io/teal.logger/main/articles/index.html -[license]: https://insightsengineering.github.io/teal.logger/main/LICENSE-text.html +[docs]: https://insightsengineering.github.io/teal.logger/latest-tag/index.html +[articles]: https://insightsengineering.github.io/teal.logger/latest-tag/articles/index.html +[license]: https://insightsengineering.github.io/teal.logger/latest-tag/LICENSE-text.html [insights]: https://github.com/insightsengineering/teal.logger/pulse diff --git a/.github/ISSUE_TEMPLATE/bug.yml b/.github/ISSUE_TEMPLATE/bug.yml index e72e354e..37a98d62 100644 --- a/.github/ISSUE_TEMPLATE/bug.yml +++ b/.github/ISSUE_TEMPLATE/bug.yml @@ -33,7 +33,7 @@ body: id: code-of-conduct attributes: label: Code of Conduct - description: By submitting this issue, you agree to follow our [Code of Conduct.](https://insightsengineering.github.io/teal.logger/CODE_OF_CONDUCT.html) + description: By submitting this issue, you agree to follow our [Code of Conduct.](https://insightsengineering.github.io/teal.logger/latest-tag/CODE_OF_CONDUCT.html) options: - label: I agree to follow this project's Code of Conduct. required: true @@ -41,7 +41,7 @@ body: id: contributor-guidelines attributes: label: Contribution Guidelines - description: By submitting this issue, you agree to follow our [Contribution Guidelines.](https://insightsengineering.github.io/teal.logger/CONTRIBUTING.html) + description: By submitting this issue, you agree to follow our [Contribution Guidelines.](https://insightsengineering.github.io/teal.logger/latest-tag/CONTRIBUTING.html) options: - label: I agree to follow this project's Contribution Guidelines. required: true diff --git a/.github/ISSUE_TEMPLATE/feature.yml b/.github/ISSUE_TEMPLATE/feature.yml index e66145dc..9cb757e1 100644 --- a/.github/ISSUE_TEMPLATE/feature.yml +++ b/.github/ISSUE_TEMPLATE/feature.yml @@ -13,7 +13,7 @@ body: id: code-of-conduct attributes: label: Code of Conduct - description: By submitting this issue, you agree to follow our [Code of Conduct.](https://insightsengineering.github.io/teal.logger/CODE_OF_CONDUCT.html) + description: By submitting this issue, you agree to follow our [Code of Conduct.](https://insightsengineering.github.io/teal.logger/latest-tag/CODE_OF_CONDUCT.html) options: - label: I agree to follow this project's Code of Conduct. required: true @@ -21,7 +21,7 @@ body: id: contributor-guidelines attributes: label: Contribution Guidelines - description: By submitting this issue, you agree to follow our [Contribution Guidelines.](https://insightsengineering.github.io/teal.logger/CONTRIBUTING.html) + description: By submitting this issue, you agree to follow our [Contribution Guidelines.](https://insightsengineering.github.io/teal.logger/latest-tag/CONTRIBUTING.html) options: - label: I agree to follow this project's Contribution Guidelines. required: true diff --git a/.github/ISSUE_TEMPLATE/question.yml b/.github/ISSUE_TEMPLATE/question.yml index 152fe3bf..37fe4036 100644 --- a/.github/ISSUE_TEMPLATE/question.yml +++ b/.github/ISSUE_TEMPLATE/question.yml @@ -13,7 +13,7 @@ body: id: code-of-conduct attributes: label: Code of Conduct - description: By submitting this issue, you agree to follow our [Code of Conduct.](https://insightsengineering.github.io/teal.logger/CODE_OF_CONDUCT.html) + description: By submitting this issue, you agree to follow our [Code of Conduct.](https://insightsengineering.github.io/teal.logger/latest-tag/CODE_OF_CONDUCT.html) options: - label: I agree to follow this project's Code of Conduct. required: true @@ -21,7 +21,7 @@ body: id: contributor-guidelines attributes: label: Contribution Guidelines - description: By submitting this issue, you agree to follow our [Contribution Guidelines.](https://insightsengineering.github.io/teal.logger/CONTRIBUTING.html) + description: By submitting this issue, you agree to follow our [Contribution Guidelines.](https://insightsengineering.github.io/teal.logger/latest-tag/CONTRIBUTING.html) options: - label: I agree to follow this project's Contribution Guidelines. required: true From c3c8c82ae053b79f5c9c00544dc9e9425a33049f Mon Sep 17 00:00:00 2001 From: m7pr Date: Tue, 18 Jun 2024 15:14:26 +0200 Subject: [PATCH 02/19] log_shiny_input_changes --- .pre-commit-config.yaml | 1 + DESCRIPTION | 4 +- NAMESPACE | 2 + R/log_shiny_input_changes.R | 96 ++++++++++++++++++++++++++++++++++ man/log_shiny_input_changes.Rd | 62 ++++++++++++++++++++++ 5 files changed, 164 insertions(+), 1 deletion(-) create mode 100644 R/log_shiny_input_changes.R create mode 100644 man/log_shiny_input_changes.Rd diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 3e808ed3..36bd8c0e 100755 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -16,6 +16,7 @@ repos: name: Regenerate package documentation additional_dependencies: - glue + - jsonlite - lifecycle - logger - shiny diff --git a/DESCRIPTION b/DESCRIPTION index f43c6f63..3a93d28c 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -19,10 +19,12 @@ Depends: R (>= 3.6) Imports: glue (>= 1.0.0), + jsonlite, lifecycle (>= 0.2.0), logger (>= 0.2.0), methods, shiny (>= 1.6.0), + utils, withr (>= 2.1.0) Suggests: knitr (>= 1.42), @@ -32,7 +34,7 @@ VignetteBuilder: knitr RdMacros: lifecycle -Config/Needs/verdepcheck: tidyverse/glue, r-lib/lifecycle, +Config/Needs/verdepcheck: tidyverse/glue, jeroen/jsonlite, r-lib/lifecycle, daroczig/logger, rstudio/shiny, r-lib/withr, yihui/knitr, rstudio/rmarkdown, r-lib/testthat Config/Needs/website: insightsengineering/nesttemplate diff --git a/NAMESPACE b/NAMESPACE index 195af755..d6e39db1 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -5,3 +5,5 @@ export(register_handlers) export(register_logger) export(suppress_logs) importFrom(lifecycle,badge) +importFrom(utils,assignInMyNamespace) +importFrom(utils,assignInNamespace) diff --git a/R/log_shiny_input_changes.R b/R/log_shiny_input_changes.R new file mode 100644 index 00000000..046514e0 --- /dev/null +++ b/R/log_shiny_input_changes.R @@ -0,0 +1,96 @@ +#' Auto logging input changes in Shiny app +#' +#' This is to be called in the \code{server} section of the Shiny app. +#' +#' Function taken from \pkg{logger} package and improved in this PR +#' [daroczig/logger/pull/155](https://github.com/daroczig/logger/pull/155/). Once this PR gets merged, the function will +#' be removed. +#' +#' @keywords internal +#' +#' @param input passed from Shiny's \code{server} +#' @param level log level +#' @param excluded_inputs character vector of input names to exclude from logging +#' @param excluded_patterns character of length one including a grep pattern of names to be excluded from logging +#' @param skip_init should initialization message be displayed +#' @param namespace the name of the namespace +#' @importFrom utils assignInMyNamespace assignInNamespace +#' @examples \dontrun{ +#' library(shiny) +#' +#' ui <- bootstrapPage( +#' numericInput("mean1", "mean1", 0), +#' numericInput("mean2", "mean2", 0), +#' numericInput("sd", "sd", 1), +#' textInput("title", "title", "title"), +#' textInput("foo", "This is not used at all, still gets logged", "foo"), +#' passwordInput("password", "Password not to be logged", "secret"), +#' plotOutput("plot") +#' ) +#' +#' server <- function(input, output) { +#' log_shiny_input_changes(input, excluded_inputs = "password", exclude_patterns = "mean") +#' +#' output$plot <- renderPlot({ +#' hist(rnorm(1e3, input$mean, input$sd), main = input$title) +#' }) +#' } +#' +#' shinyApp(ui = ui, server = server) +#' } +log_shiny_input_changes <- function( + input, + level = logger::INFO, + namespace = NA_character_, + excluded_inputs = character(), + excluded_patterns = character(), + skip_init = FALSE + ) { + + if (!(shiny::isRunning() | inherits(session, "MockShinySession"))) { + stop("No Shiny app running, it makes no sense to call this function outside of a Shiny app") + } + + session <- shiny::getDefaultReactiveDomain() + ns <- if (!is.null(session)) session$ns(character(0)) + + input_values <- shiny::isolate(shiny::reactiveValuesToList(input)) + utils::assignInMyNamespace("shiny_input_values", input_values) + + if (!skip_init) { + init_message <- + paste( + ns, "Default Shiny inputs initialized:", + as.character(jsonlite::toJSON(input_values, auto_unbox = TRUE)) + ) + + logger::log_level( + level, + logger::skip_formatter(trimws(init_message)), + namespace = namespace + ) + } + + shiny::observe({ + old_input_values <- shiny_input_values + new_input_values <- shiny::reactiveValuesToList(input) + names <- unique(c(names(old_input_values), names(new_input_values))) + names <- setdiff(names, excluded_inputs) + if (length(excluded_patterns)) { + names <- grep(excluded_patterns, names, invert = TRUE, value = TRUE) + } + for (name in names) { + old <- old_input_values[name] + new <- new_input_values[name] + if (!identical(old, new)) { + message <- ifelse(is.null(ns), + "Shiny input change detected in {name}: {old} -> {new}", + "Shiny input change detected in {ns} on {name}: {old} -> {new}" + ) + logger::log_level(level, message, namespace = namespace) + } + } + utils::assignInNamespace("shiny_input_values", new_input_values, ns = "logger") + }) +} +shiny_input_values <- NULL diff --git a/man/log_shiny_input_changes.Rd b/man/log_shiny_input_changes.Rd new file mode 100644 index 00000000..21870907 --- /dev/null +++ b/man/log_shiny_input_changes.Rd @@ -0,0 +1,62 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/log_shiny_input_changes.R +\name{log_shiny_input_changes} +\alias{log_shiny_input_changes} +\title{Auto logging input changes in Shiny app} +\usage{ +log_shiny_input_changes( + input, + level = logger::INFO, + namespace = NA_character_, + excluded_inputs = character(), + excluded_patterns = character(), + skip_init = FALSE +) +} +\arguments{ +\item{input}{passed from Shiny's \code{server}} + +\item{level}{log level} + +\item{namespace}{the name of the namespace} + +\item{excluded_inputs}{character vector of input names to exclude from logging} + +\item{excluded_patterns}{character of length one including a grep pattern of names to be excluded from logging} + +\item{skip_init}{should initialization message be displayed} +} +\description{ +This is to be called in the \code{server} section of the Shiny app. +} +\details{ +Function taken from \pkg{logger} package and improved in this PR +\href{https://github.com/daroczig/logger/pull/155/}{daroczig/logger/pull/155}. Once this PR gets merged, the function will +be removed. +} +\examples{ +\dontrun{ +library(shiny) + +ui <- bootstrapPage( + numericInput("mean1", "mean1", 0), + numericInput("mean2", "mean2", 0), + numericInput("sd", "sd", 1), + textInput("title", "title", "title"), + textInput("foo", "This is not used at all, still gets logged", "foo"), + passwordInput("password", "Password not to be logged", "secret"), + plotOutput("plot") +) + +server <- function(input, output) { + log_shiny_input_changes(input, excluded_inputs = "password", exclude_patterns = "mean") + + output$plot <- renderPlot({ + hist(rnorm(1e3, input$mean, input$sd), main = input$title) + }) +} + +shinyApp(ui = ui, server = server) +} +} +\keyword{internal} From c01a32a2f92367db39a3b6468236522419f6351b Mon Sep 17 00:00:00 2001 From: m7pr Date: Tue, 18 Jun 2024 15:31:35 +0200 Subject: [PATCH 03/19] session should be defined first --- R/log_shiny_input_changes.R | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/R/log_shiny_input_changes.R b/R/log_shiny_input_changes.R index 046514e0..24c81543 100644 --- a/R/log_shiny_input_changes.R +++ b/R/log_shiny_input_changes.R @@ -47,11 +47,10 @@ log_shiny_input_changes <- function( skip_init = FALSE ) { + session <- shiny::getDefaultReactiveDomain() if (!(shiny::isRunning() | inherits(session, "MockShinySession"))) { stop("No Shiny app running, it makes no sense to call this function outside of a Shiny app") } - - session <- shiny::getDefaultReactiveDomain() ns <- if (!is.null(session)) session$ns(character(0)) input_values <- shiny::isolate(shiny::reactiveValuesToList(input)) From 9abdb481b9a545c97e4ba7da9e530593ab6137c0 Mon Sep 17 00:00:00 2001 From: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Tue, 18 Jun 2024 14:02:26 +0000 Subject: [PATCH 04/19] [skip style] [skip vbump] Restyle files --- R/log_shiny_input_changes.R | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/R/log_shiny_input_changes.R b/R/log_shiny_input_changes.R index 24c81543..eabe4cc8 100644 --- a/R/log_shiny_input_changes.R +++ b/R/log_shiny_input_changes.R @@ -44,9 +44,7 @@ log_shiny_input_changes <- function( namespace = NA_character_, excluded_inputs = character(), excluded_patterns = character(), - skip_init = FALSE - ) { - + skip_init = FALSE) { session <- shiny::getDefaultReactiveDomain() if (!(shiny::isRunning() | inherits(session, "MockShinySession"))) { stop("No Shiny app running, it makes no sense to call this function outside of a Shiny app") From c59363228fd781c67c71fb7f96f3de593c39bf0d Mon Sep 17 00:00:00 2001 From: m7pr Date: Tue, 18 Jun 2024 17:30:15 +0200 Subject: [PATCH 05/19] release the kraken --- NAMESPACE | 2 -- NEWS.md | 3 +++ R/log_shiny_input_changes.R | 43 +++++++--------------------------- man/log_shiny_input_changes.Rd | 13 ++-------- 4 files changed, 13 insertions(+), 48 deletions(-) diff --git a/NAMESPACE b/NAMESPACE index d6e39db1..195af755 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -5,5 +5,3 @@ export(register_handlers) export(register_logger) export(suppress_logs) importFrom(lifecycle,badge) -importFrom(utils,assignInMyNamespace) -importFrom(utils,assignInNamespace) diff --git a/NEWS.md b/NEWS.md index c8526311..16fe11e8 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,8 @@ # teal.logger 0.2.0.9003 +* New function `log_shiny_input_changes` based on `logger` implementation, but curated to `teal` needs. +It allows to track all shiny inputs changes in teal modules on `TRACE` level with appended namespace name. + # teal.logger 0.2.0 * New function `register_handlers` to register global handlers for logging messages, warnings and errors. diff --git a/R/log_shiny_input_changes.R b/R/log_shiny_input_changes.R index 24c81543..8564c0ae 100644 --- a/R/log_shiny_input_changes.R +++ b/R/log_shiny_input_changes.R @@ -2,20 +2,14 @@ #' #' This is to be called in the \code{server} section of the Shiny app. #' -#' Function taken from \pkg{logger} package and improved in this PR -#' [daroczig/logger/pull/155](https://github.com/daroczig/logger/pull/155/). Once this PR gets merged, the function will -#' be removed. -#' -#' @keywords internal +#' Function having very similar behavior as [logger::log_shiny_input_changes()] but adjusted for `teal` needs. #' #' @param input passed from Shiny's \code{server} -#' @param level log level #' @param excluded_inputs character vector of input names to exclude from logging #' @param excluded_patterns character of length one including a grep pattern of names to be excluded from logging -#' @param skip_init should initialization message be displayed #' @param namespace the name of the namespace -#' @importFrom utils assignInMyNamespace assignInNamespace -#' @examples \dontrun{ +#' @examples +#' \dontrun{ #' library(shiny) #' #' ui <- bootstrapPage( @@ -40,11 +34,9 @@ #' } log_shiny_input_changes <- function( input, - level = logger::INFO, namespace = NA_character_, excluded_inputs = character(), - excluded_patterns = character(), - skip_init = FALSE + excluded_patterns = "_width$" ) { session <- shiny::getDefaultReactiveDomain() @@ -53,22 +45,7 @@ log_shiny_input_changes <- function( } ns <- if (!is.null(session)) session$ns(character(0)) - input_values <- shiny::isolate(shiny::reactiveValuesToList(input)) - utils::assignInMyNamespace("shiny_input_values", input_values) - - if (!skip_init) { - init_message <- - paste( - ns, "Default Shiny inputs initialized:", - as.character(jsonlite::toJSON(input_values, auto_unbox = TRUE)) - ) - - logger::log_level( - level, - logger::skip_formatter(trimws(init_message)), - namespace = namespace - ) - } + shiny_input_values <- shiny::isolate(shiny::reactiveValuesToList(input)) shiny::observe({ old_input_values <- shiny_input_values @@ -82,14 +59,10 @@ log_shiny_input_changes <- function( old <- old_input_values[name] new <- new_input_values[name] if (!identical(old, new)) { - message <- ifelse(is.null(ns), - "Shiny input change detected in {name}: {old} -> {new}", - "Shiny input change detected in {ns} on {name}: {old} -> {new}" - ) - logger::log_level(level, message, namespace = namespace) + message <- trimws(paste(ns, "Shiny input change detected in {name}: {old} -> {new}")) + logger::log_level(logger::TRACE, message, namespace = namespace) } } - utils::assignInNamespace("shiny_input_values", new_input_values, ns = "logger") + shiny_input_values <- new_input_values }) } -shiny_input_values <- NULL diff --git a/man/log_shiny_input_changes.Rd b/man/log_shiny_input_changes.Rd index 21870907..f8d4e37d 100644 --- a/man/log_shiny_input_changes.Rd +++ b/man/log_shiny_input_changes.Rd @@ -6,33 +6,25 @@ \usage{ log_shiny_input_changes( input, - level = logger::INFO, namespace = NA_character_, excluded_inputs = character(), - excluded_patterns = character(), - skip_init = FALSE + excluded_patterns = "_width$" ) } \arguments{ \item{input}{passed from Shiny's \code{server}} -\item{level}{log level} - \item{namespace}{the name of the namespace} \item{excluded_inputs}{character vector of input names to exclude from logging} \item{excluded_patterns}{character of length one including a grep pattern of names to be excluded from logging} - -\item{skip_init}{should initialization message be displayed} } \description{ This is to be called in the \code{server} section of the Shiny app. } \details{ -Function taken from \pkg{logger} package and improved in this PR -\href{https://github.com/daroczig/logger/pull/155/}{daroczig/logger/pull/155}. Once this PR gets merged, the function will -be removed. +Function having very similar behavior as \code{\link[logger:log_shiny_input_changes]{logger::log_shiny_input_changes()}} but adjusted for \code{teal} needs. } \examples{ \dontrun{ @@ -59,4 +51,3 @@ server <- function(input, output) { shinyApp(ui = ui, server = server) } } -\keyword{internal} From 7cd44da70d21c8f9c82b5be4b37e3b7ab6f2fbb9 Mon Sep 17 00:00:00 2001 From: m7pr Date: Tue, 18 Jun 2024 17:33:35 +0200 Subject: [PATCH 06/19] export log_shiny_input_changes --- NAMESPACE | 1 + R/log_shiny_input_changes.R | 1 + 2 files changed, 2 insertions(+) diff --git a/NAMESPACE b/NAMESPACE index 195af755..ab0f1610 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,5 +1,6 @@ # Generated by roxygen2: do not edit by hand +export(log_shiny_input_changes) export(log_system_info) export(register_handlers) export(register_logger) diff --git a/R/log_shiny_input_changes.R b/R/log_shiny_input_changes.R index 26ce249b..7cffa7e9 100644 --- a/R/log_shiny_input_changes.R +++ b/R/log_shiny_input_changes.R @@ -32,6 +32,7 @@ #' #' shinyApp(ui = ui, server = server) #' } +#' @export log_shiny_input_changes <- function( input, namespace = NA_character_, From edb3219cc32c5346b2bbf9aa59f9806fdcc734af Mon Sep 17 00:00:00 2001 From: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Tue, 18 Jun 2024 15:35:42 +0000 Subject: [PATCH 07/19] [skip style] [skip vbump] Restyle files --- R/log_shiny_input_changes.R | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/R/log_shiny_input_changes.R b/R/log_shiny_input_changes.R index 7cffa7e9..2b8b095f 100644 --- a/R/log_shiny_input_changes.R +++ b/R/log_shiny_input_changes.R @@ -37,8 +37,7 @@ log_shiny_input_changes <- function( input, namespace = NA_character_, excluded_inputs = character(), - excluded_patterns = "_width$" - ) { + excluded_patterns = "_width$") { session <- shiny::getDefaultReactiveDomain() if (!(shiny::isRunning() | inherits(session, "MockShinySession"))) { stop("No Shiny app running, it makes no sense to call this function outside of a Shiny app") From 507b6ecb15ec1fc43c63a3b94b596e46ddd51523 Mon Sep 17 00:00:00 2001 From: Marcin <133694481+m7pr@users.noreply.github.com> Date: Tue, 18 Jun 2024 17:58:04 +0200 Subject: [PATCH 08/19] Update R/log_shiny_input_changes.R Co-authored-by: Pawel Rucki <12943682+pawelru@users.noreply.github.com> Signed-off-by: Marcin <133694481+m7pr@users.noreply.github.com> --- R/log_shiny_input_changes.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/log_shiny_input_changes.R b/R/log_shiny_input_changes.R index 2b8b095f..b9fc4f3d 100644 --- a/R/log_shiny_input_changes.R +++ b/R/log_shiny_input_changes.R @@ -59,7 +59,7 @@ log_shiny_input_changes <- function( new <- new_input_values[name] if (!identical(old, new)) { message <- trimws(paste(ns, "Shiny input change detected in {name}: {old} -> {new}")) - logger::log_level(logger::TRACE, message, namespace = namespace) + logger::log_trace(message, namespace = namespace) } } shiny_input_values <- new_input_values From 1849ba317f7e859681106c5f54db4716007440ac Mon Sep 17 00:00:00 2001 From: m7pr Date: Tue, 18 Jun 2024 18:00:24 +0200 Subject: [PATCH 09/19] extend pkgdown --- _pkgdown.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/_pkgdown.yml b/_pkgdown.yml index a6935ee4..22e29bdf 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -28,3 +28,4 @@ reference: - register_logger - register_handlers - suppress_logs + - log_shiny_input_changes From fa9f82643db0b674ba372975d7352e8de2db46fa Mon Sep 17 00:00:00 2001 From: m7pr Date: Tue, 18 Jun 2024 18:06:51 +0200 Subject: [PATCH 10/19] remove jsonlite dependency --- .pre-commit-config.yaml | 1 - DESCRIPTION | 3 +-- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 36bd8c0e..3e808ed3 100755 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -16,7 +16,6 @@ repos: name: Regenerate package documentation additional_dependencies: - glue - - jsonlite - lifecycle - logger - shiny diff --git a/DESCRIPTION b/DESCRIPTION index 3a93d28c..c24968ab 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -19,7 +19,6 @@ Depends: R (>= 3.6) Imports: glue (>= 1.0.0), - jsonlite, lifecycle (>= 0.2.0), logger (>= 0.2.0), methods, @@ -34,7 +33,7 @@ VignetteBuilder: knitr RdMacros: lifecycle -Config/Needs/verdepcheck: tidyverse/glue, jeroen/jsonlite, r-lib/lifecycle, +Config/Needs/verdepcheck: tidyverse/glue, r-lib/lifecycle, daroczig/logger, rstudio/shiny, r-lib/withr, yihui/knitr, rstudio/rmarkdown, r-lib/testthat Config/Needs/website: insightsengineering/nesttemplate From b66a3eee5b9971050871d4e3957d82c1b6680773 Mon Sep 17 00:00:00 2001 From: m7pr Date: Tue, 18 Jun 2024 18:08:24 +0200 Subject: [PATCH 11/19] lintr and spellcheck --- R/log_shiny_input_changes.R | 4 ++-- man/log_shiny_input_changes.Rd | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/R/log_shiny_input_changes.R b/R/log_shiny_input_changes.R index b9fc4f3d..1e164777 100644 --- a/R/log_shiny_input_changes.R +++ b/R/log_shiny_input_changes.R @@ -4,7 +4,7 @@ #' #' Function having very similar behavior as [logger::log_shiny_input_changes()] but adjusted for `teal` needs. #' -#' @param input passed from Shiny's \code{server} +#' @param input passed from Shiny \code{server} #' @param excluded_inputs character vector of input names to exclude from logging #' @param excluded_patterns character of length one including a grep pattern of names to be excluded from logging #' @param namespace the name of the namespace @@ -39,7 +39,7 @@ log_shiny_input_changes <- function( excluded_inputs = character(), excluded_patterns = "_width$") { session <- shiny::getDefaultReactiveDomain() - if (!(shiny::isRunning() | inherits(session, "MockShinySession"))) { + if (!(shiny::isRunning() || inherits(session, "MockShinySession"))) { stop("No Shiny app running, it makes no sense to call this function outside of a Shiny app") } ns <- if (!is.null(session)) session$ns(character(0)) diff --git a/man/log_shiny_input_changes.Rd b/man/log_shiny_input_changes.Rd index f8d4e37d..4bbed786 100644 --- a/man/log_shiny_input_changes.Rd +++ b/man/log_shiny_input_changes.Rd @@ -12,7 +12,7 @@ log_shiny_input_changes( ) } \arguments{ -\item{input}{passed from Shiny's \code{server}} +\item{input}{passed from Shiny \code{server}} \item{namespace}{the name of the namespace} From fe680dd7df7f09c38e7b16893dfd34117f56955c Mon Sep 17 00:00:00 2001 From: Marcin <133694481+m7pr@users.noreply.github.com> Date: Wed, 19 Jun 2024 09:47:57 +0200 Subject: [PATCH 12/19] Update DESCRIPTION Co-authored-by: Pawel Rucki <12943682+pawelru@users.noreply.github.com> Signed-off-by: Marcin <133694481+m7pr@users.noreply.github.com> --- DESCRIPTION | 1 - 1 file changed, 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index c24968ab..f43c6f63 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -23,7 +23,6 @@ Imports: logger (>= 0.2.0), methods, shiny (>= 1.6.0), - utils, withr (>= 2.1.0) Suggests: knitr (>= 1.42), From 93427487f46c97e751c00ed327ad8b1144469298 Mon Sep 17 00:00:00 2001 From: Marcin <133694481+m7pr@users.noreply.github.com> Date: Wed, 19 Jun 2024 09:48:29 +0200 Subject: [PATCH 13/19] Update R/log_shiny_input_changes.R Co-authored-by: Pawel Rucki <12943682+pawelru@users.noreply.github.com> Signed-off-by: Marcin <133694481+m7pr@users.noreply.github.com> --- R/log_shiny_input_changes.R | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/R/log_shiny_input_changes.R b/R/log_shiny_input_changes.R index 1e164777..1481d615 100644 --- a/R/log_shiny_input_changes.R +++ b/R/log_shiny_input_changes.R @@ -34,10 +34,11 @@ #' } #' @export log_shiny_input_changes <- function( - input, - namespace = NA_character_, - excluded_inputs = character(), - excluded_patterns = "_width$") { + input, + namespace = NA_character_, + excluded_inputs = character(), + excluded_patterns = "_width$" +) { session <- shiny::getDefaultReactiveDomain() if (!(shiny::isRunning() || inherits(session, "MockShinySession"))) { stop("No Shiny app running, it makes no sense to call this function outside of a Shiny app") From 4b1f292e3ca4679af935464e57058c308385240c Mon Sep 17 00:00:00 2001 From: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Wed, 19 Jun 2024 07:50:20 +0000 Subject: [PATCH 14/19] [skip style] [skip vbump] Restyle files --- R/log_shiny_input_changes.R | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/R/log_shiny_input_changes.R b/R/log_shiny_input_changes.R index 1481d615..1e164777 100644 --- a/R/log_shiny_input_changes.R +++ b/R/log_shiny_input_changes.R @@ -34,11 +34,10 @@ #' } #' @export log_shiny_input_changes <- function( - input, - namespace = NA_character_, - excluded_inputs = character(), - excluded_patterns = "_width$" -) { + input, + namespace = NA_character_, + excluded_inputs = character(), + excluded_patterns = "_width$") { session <- shiny::getDefaultReactiveDomain() if (!(shiny::isRunning() || inherits(session, "MockShinySession"))) { stop("No Shiny app running, it makes no sense to call this function outside of a Shiny app") From 39c7e2d493f43e3ee3b2a17eefef6ef5b4e95b0e Mon Sep 17 00:00:00 2001 From: m7pr Date: Wed, 19 Jun 2024 09:52:54 +0200 Subject: [PATCH 15/19] use ns as glue syntax --- R/log_shiny_input_changes.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/R/log_shiny_input_changes.R b/R/log_shiny_input_changes.R index 1481d615..8a9fc85d 100644 --- a/R/log_shiny_input_changes.R +++ b/R/log_shiny_input_changes.R @@ -43,7 +43,7 @@ log_shiny_input_changes <- function( if (!(shiny::isRunning() || inherits(session, "MockShinySession"))) { stop("No Shiny app running, it makes no sense to call this function outside of a Shiny app") } - ns <- if (!is.null(session)) session$ns(character(0)) + ns <- ifelse(!is.null(session), session$ns(character(0)), "") shiny_input_values <- shiny::isolate(shiny::reactiveValuesToList(input)) @@ -59,7 +59,7 @@ log_shiny_input_changes <- function( old <- old_input_values[name] new <- new_input_values[name] if (!identical(old, new)) { - message <- trimws(paste(ns, "Shiny input change detected in {name}: {old} -> {new}")) + message <- trimws("{ns} Shiny input change detected in {name}: {old} -> {new}") logger::log_trace(message, namespace = namespace) } } From 44e144b901f398cabbb58ece41ec82f856bc8707 Mon Sep 17 00:00:00 2001 From: m7pr Date: Wed, 19 Jun 2024 10:14:09 +0200 Subject: [PATCH 16/19] bring back utils solution --- DESCRIPTION | 1 + R/log_shiny_input_changes.R | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index f43c6f63..c24968ab 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -23,6 +23,7 @@ Imports: logger (>= 0.2.0), methods, shiny (>= 1.6.0), + utils, withr (>= 2.1.0) Suggests: knitr (>= 1.42), diff --git a/R/log_shiny_input_changes.R b/R/log_shiny_input_changes.R index 2d5426a3..0e7e6ba4 100644 --- a/R/log_shiny_input_changes.R +++ b/R/log_shiny_input_changes.R @@ -44,7 +44,10 @@ log_shiny_input_changes <- function( } ns <- ifelse(!is.null(session), session$ns(character(0)), "") - shiny_input_values <- shiny::isolate(shiny::reactiveValuesToList(input)) + # utils::assignInMyNamespace and utils::assignInNamespace are needed + # so that observer is executed only once, not twice. + input_values <- shiny::isolate(shiny::reactiveValuesToList(input)) + utils::assignInMyNamespace('shiny_input_values', input_values) shiny::observe({ old_input_values <- shiny_input_values @@ -62,6 +65,7 @@ log_shiny_input_changes <- function( logger::log_trace(message, namespace = namespace) } } - shiny_input_values <- new_input_values + utils::assignInNamespace('shiny_input_values', new_input_values, ns = 'teal.logger') }) } +shiny_input_values <- NULL From bf578090d5d23c72d723e62e44370d61ab9d581d Mon Sep 17 00:00:00 2001 From: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Wed, 19 Jun 2024 08:16:01 +0000 Subject: [PATCH 17/19] [skip style] [skip vbump] Restyle files --- R/log_shiny_input_changes.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/R/log_shiny_input_changes.R b/R/log_shiny_input_changes.R index 0e7e6ba4..7b6d8b21 100644 --- a/R/log_shiny_input_changes.R +++ b/R/log_shiny_input_changes.R @@ -47,7 +47,7 @@ log_shiny_input_changes <- function( # utils::assignInMyNamespace and utils::assignInNamespace are needed # so that observer is executed only once, not twice. input_values <- shiny::isolate(shiny::reactiveValuesToList(input)) - utils::assignInMyNamespace('shiny_input_values', input_values) + utils::assignInMyNamespace("shiny_input_values", input_values) shiny::observe({ old_input_values <- shiny_input_values @@ -65,7 +65,7 @@ log_shiny_input_changes <- function( logger::log_trace(message, namespace = namespace) } } - utils::assignInNamespace('shiny_input_values', new_input_values, ns = 'teal.logger') + utils::assignInNamespace("shiny_input_values", new_input_values, ns = "teal.logger") }) } shiny_input_values <- NULL From 9a52a5194bd6b8dc8c5d84e99bbc1e66c507f843 Mon Sep 17 00:00:00 2001 From: m7pr Date: Wed, 19 Jun 2024 11:36:56 +0200 Subject: [PATCH 18/19] excluded_pattern as singular word --- R/log_shiny_input_changes.R | 8 ++++---- man/log_shiny_input_changes.Rd | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/R/log_shiny_input_changes.R b/R/log_shiny_input_changes.R index 0e7e6ba4..da462bf1 100644 --- a/R/log_shiny_input_changes.R +++ b/R/log_shiny_input_changes.R @@ -6,7 +6,7 @@ #' #' @param input passed from Shiny \code{server} #' @param excluded_inputs character vector of input names to exclude from logging -#' @param excluded_patterns character of length one including a grep pattern of names to be excluded from logging +#' @param excluded_pattern character of length one including a grep pattern of names to be excluded from logging #' @param namespace the name of the namespace #' @examples #' \dontrun{ @@ -37,7 +37,7 @@ log_shiny_input_changes <- function( input, namespace = NA_character_, excluded_inputs = character(), - excluded_patterns = "_width$") { + excluded_pattern = "_width$") { session <- shiny::getDefaultReactiveDomain() if (!(shiny::isRunning() || inherits(session, "MockShinySession"))) { stop("No Shiny app running, it makes no sense to call this function outside of a Shiny app") @@ -54,8 +54,8 @@ log_shiny_input_changes <- function( new_input_values <- shiny::reactiveValuesToList(input) names <- unique(c(names(old_input_values), names(new_input_values))) names <- setdiff(names, excluded_inputs) - if (length(excluded_patterns)) { - names <- grep(excluded_patterns, names, invert = TRUE, value = TRUE) + if (length(excluded_pattern)) { + names <- grep(excluded_pattern, names, invert = TRUE, value = TRUE) } for (name in names) { old <- old_input_values[name] diff --git a/man/log_shiny_input_changes.Rd b/man/log_shiny_input_changes.Rd index 4bbed786..57f4c0cb 100644 --- a/man/log_shiny_input_changes.Rd +++ b/man/log_shiny_input_changes.Rd @@ -8,7 +8,7 @@ log_shiny_input_changes( input, namespace = NA_character_, excluded_inputs = character(), - excluded_patterns = "_width$" + excluded_pattern = "_width$" ) } \arguments{ @@ -18,7 +18,7 @@ log_shiny_input_changes( \item{excluded_inputs}{character vector of input names to exclude from logging} -\item{excluded_patterns}{character of length one including a grep pattern of names to be excluded from logging} +\item{excluded_pattern}{character of length one including a grep pattern of names to be excluded from logging} } \description{ This is to be called in the \code{server} section of the Shiny app. From 049e630a8fb9948e5be86b5f575b3a691e6810d5 Mon Sep 17 00:00:00 2001 From: m7pr Date: Wed, 19 Jun 2024 11:44:02 +0200 Subject: [PATCH 19/19] typo in example --- R/log_shiny_input_changes.R | 2 +- man/log_shiny_input_changes.Rd | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/R/log_shiny_input_changes.R b/R/log_shiny_input_changes.R index 86ff6971..6f959f98 100644 --- a/R/log_shiny_input_changes.R +++ b/R/log_shiny_input_changes.R @@ -23,7 +23,7 @@ #' ) #' #' server <- function(input, output) { -#' log_shiny_input_changes(input, excluded_inputs = "password", exclude_patterns = "mean") +#' log_shiny_input_changes(input, excluded_inputs = "password", excluded_pattern = "mean") #' #' output$plot <- renderPlot({ #' hist(rnorm(1e3, input$mean, input$sd), main = input$title) diff --git a/man/log_shiny_input_changes.Rd b/man/log_shiny_input_changes.Rd index 57f4c0cb..e2643e1b 100644 --- a/man/log_shiny_input_changes.Rd +++ b/man/log_shiny_input_changes.Rd @@ -41,7 +41,7 @@ ui <- bootstrapPage( ) server <- function(input, output) { - log_shiny_input_changes(input, excluded_inputs = "password", exclude_patterns = "mean") + log_shiny_input_changes(input, excluded_inputs = "password", excluded_pattern = "mean") output$plot <- renderPlot({ hist(rnorm(1e3, input$mean, input$sd), main = input$title)