diff --git a/NEWS.md b/NEWS.md index fcd924e..3d27f6f 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,7 @@ # reactlog (development) +- `reactlog_show()` now uses `shiny::reactlog()` as its default `log`, so `reactlog_show()` works with no arguments after running an app (#91) + - Migrated project license from GPL-3 to the MIT License. - Documented that `reactlog_show()` passes `...` on to `reactlog_render()`, so `session_token` can be set from `reactlog_show()`. The docs used to say `...` was ignored (#120) diff --git a/R/showReactLog.R b/R/showReactLog.R index e0d360f..80650cd 100644 --- a/R/showReactLog.R +++ b/R/showReactLog.R @@ -35,7 +35,8 @@ #' enabled, it's possible for any user of your app to see at least some #' of the source code of your reactive expressions and observers. #' -#' @param log Log produced by shiny to be processed +#' @param log Log produced by shiny to be processed. Defaults to +#' [shiny::reactlog()], the log recorded in the current R session. #' @param time A boolean that specifies whether or not to display the #' time that each reactive takes to calculate a result. #' @param ... Arguments passed on to `reactlog_render()`, such as `session_token`. @@ -56,10 +57,10 @@ #' runApp(app) #' #' # once app has closed, display reactlog -#' shiny::reactlogShow() +#' reactlog_show() #' } -reactlog_show <- function(log, time = TRUE, ...) { +reactlog_show <- function(log = shiny::reactlog(), time = TRUE, ...) { file <- reactlog_render(log, time = as.logical(time), ...) utils::browseURL(file) } diff --git a/man/reactlog_show.Rd b/man/reactlog_show.Rd index 43ce78d..b29d177 100644 --- a/man/reactlog_show.Rd +++ b/man/reactlog_show.Rd @@ -7,10 +7,11 @@ \usage{ reactlog_render(log, session_token = NULL, time = TRUE) -reactlog_show(log, time = TRUE, ...) +reactlog_show(log = shiny::reactlog(), time = TRUE, ...) } \arguments{ -\item{log}{Log produced by shiny to be processed} +\item{log}{Log produced by shiny to be processed. Defaults to +\code{\link[shiny:reactlog]{shiny::reactlog()}}, the log recorded in the current R session.} \item{session_token}{token to be used to subset which session is displayed. Defaults to all sessions.} @@ -68,7 +69,7 @@ app <- system.file("examples/01_hello", package = "shiny") runApp(app) # once app has closed, display reactlog -shiny::reactlogShow() +reactlog_show() } } \seealso{ diff --git a/tests/testthat/test-render.R b/tests/testthat/test-render.R index 6568da8..a0fc4e0 100644 --- a/tests/testthat/test-render.R +++ b/tests/testthat/test-render.R @@ -17,3 +17,18 @@ test_that("reactlog_show() passes ... to reactlog_render()", { # no message match: "unused argument" is translated in other locales expect_error(reactlog_show(log, foo = 1)) }) + +test_that("reactlog_show() defaults to shiny::reactlog()", { + skip_if_not_installed("shiny") + called <- FALSE + local_mocked_bindings( + reactlog = function() { + called <<- TRUE + structure(list(), version = "1") + }, + .package = "shiny" + ) + local_mocked_bindings(browseURL = function(...) NULL, .package = "utils") + reactlog_show() + expect_true(called) +})