From 6e28f8ab75581298dc8d97c8077de3d61addff68 Mon Sep 17 00:00:00 2001 From: Ashley Baldry Date: Wed, 4 Feb 2026 17:28:23 +0000 Subject: [PATCH 1/4] Rename shinyrepro to shinyreprex --- DESCRIPTION | 6 +++--- NEWS.md | 4 ++-- README.md | 12 ++++++------ _pkgdown.yml | 2 +- tests/testthat.R | 4 ++-- tests/testthat/test-call_chunk_utils.R | 2 +- vignettes/shinyrepro.Rmd | 8 ++++---- 7 files changed, 19 insertions(+), 19 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 385e1e4..7d750bc 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,4 +1,4 @@ -Package: shinyrepro +Package: shinyreprex Type: Package Title: Reproducible Code for 'Shiny' Objects Version: 0.1.0 @@ -8,8 +8,8 @@ Description: Provides functionality to extract reactive expressions from a 'Shin outside the interactive UI, facilitating integration into static reports or automated workflows without requiring access to the original application source code. License: MIT + file LICENSE -URL: https://github.com/AscentSoftware/shinyrepro, https://jubilant-dollop-5lekoky.pages.github.io -BugReports: https://github.com/AscentSoftware/shinyrepro/issues +URL: https://github.com/AscentSoftware/shinyreprex, https://ascentsoftware.github.io/shinyrepro/ +BugReports: https://github.com/AscentSoftware/shinyreprex/issues Depends: R (>= 4.3.0) Imports: diff --git a/NEWS.md b/NEWS.md index e19b2cc..3e0e3c8 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,3 @@ -# shinyrepro 0.1.0 +# shinyreprex 0.1.0 -* This is the first release of shinyrepro +* This is the first release of shinyreprex diff --git a/README.md b/README.md index 84184c1..fb7fc9a 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,12 @@ -# shinyrepro +# shinyreprex -[![R-CMD-check](https://github.com/AscentSoftware/shinyrepro/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/AscentSoftware/shinyrepro/actions/workflows/R-CMD-check.yaml) +[![R-CMD-check](https://github.com/AscentSoftware/shinyreprex/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/AscentSoftware/shinyreprex/actions/workflows/R-CMD-check.yaml) ## Overview -The aim of **shinyrepro** is to be able to recreate any reactive or output that is available in +The aim of **shinyreprex** is to be able to recreate any reactive or output that is available in a Shiny application outside of said application. In static documents, like Quarto, it is easy to include the code chunk by including code folding. @@ -16,11 +16,11 @@ environment outside of Shiny. ## Installation -To get the latest version of shinyrepro, install from GitHub: +To get the latest version of shinyreprex, install from GitHub: ```r require(remotes) -remotes::install_github("AscentSoftware/shinyrepro") +remotes::install_github("AscentSoftware/shinyreprex") ``` ## Usage @@ -31,7 +31,7 @@ the code that generates the table seen in the UI. ```r library(shiny) -library(shinyrepro) +library(shinyreprex) ui <- fluidPage( h1("Reproducible Code Example"), diff --git a/_pkgdown.yml b/_pkgdown.yml index 274e57f..1e2d364 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -1,4 +1,4 @@ -url: https://ascentsoftware.github.io/shinyrepro/ +url: https://ascentsoftware.github.io/shinyreprex/ template: package: ascentdown bootstrap: 5 diff --git a/tests/testthat.R b/tests/testthat.R index 1976e85..fd010de 100644 --- a/tests/testthat.R +++ b/tests/testthat.R @@ -7,6 +7,6 @@ # * https://testthat.r-lib.org/articles/special-files.html library(testthat) -library(shinyrepro) +library(shinyreprex) -test_check("shinyrepro") +test_check("shinyreprex") diff --git a/tests/testthat/test-call_chunk_utils.R b/tests/testthat/test-call_chunk_utils.R index 6f28fbc..256de02 100644 --- a/tests/testthat/test-call_chunk_utils.R +++ b/tests/testthat/test-call_chunk_utils.R @@ -4,7 +4,7 @@ test_that("Able to extract package name from pkg::fn call", { }) test_that("Able to extract package name from unnamespaced function call", { - expect_identical(get_pkg_name(str2lang("repro_chunk('foo')")), "shinyrepro") + expect_identical(get_pkg_name(str2lang("repro_chunk('foo')")), "shinyreprex") }) test_that("When extract package from function call, base R packages are ignored", { diff --git a/vignettes/shinyrepro.Rmd b/vignettes/shinyrepro.Rmd index f9839cb..babdf49 100644 --- a/vignettes/shinyrepro.Rmd +++ b/vignettes/shinyrepro.Rmd @@ -1,8 +1,8 @@ --- -title: "Introduction to shinyrepro" +title: "Introduction to shinyreprex" output: rmarkdown::html_vignette vignette: > - %\VignetteIndexEntry{Introduction to shinyrepro} + %\VignetteIndexEntry{Introduction to shinyreprex} %\VignetteEngine{knitr::rmarkdown} %\VignetteEncoding{UTF-8} --- @@ -13,10 +13,10 @@ knitr::opts_chunk$set( comment = "#>" ) -library(shinyrepro) +library(shinyreprex) ``` -## Using shinyrepro +## Using shinyreprex There is a single exported function, `repro`, that takes a reactive object and converts it into a script that can be reused outside of the Shiny application to reproduce the result From afe2155598bb507c4e79a6191aba1a060137a21d Mon Sep 17 00:00:00 2001 From: Ashley Baldry Date: Wed, 4 Feb 2026 18:06:09 +0000 Subject: [PATCH 2/4] Rename repro to reprex_shiny --- R/repro.R | 2 +- README.md | 2 +- man/repro.Rd | 2 +- tests/testthat/test-call_chunk_function.R | 4 ++-- tests/testthat/test-call_chunk_if.R | 8 +++---- tests/testthat/test-call_chunk_null.R | 2 +- tests/testthat/test-chunk_reactive.R | 10 ++++----- tests/testthat/test-repro.R | 26 +++++++++++------------ vignettes/shinyrepro.Rmd | 4 ++-- 9 files changed, 30 insertions(+), 30 deletions(-) diff --git a/R/repro.R b/R/repro.R index dada60d..c95fc1a 100644 --- a/R/repro.R +++ b/R/repro.R @@ -59,7 +59,7 @@ #' }) #' #' output$table <- renderTable(summary_tbl()) -#' output$code <- renderText(repro(summary_tbl)) +#' output$code <- renderText(reprex_reactivesummary_tbl)) #' } #' #' if (interactive()) { diff --git a/README.md b/README.md index fb7fc9a..4310b9c 100644 --- a/README.md +++ b/README.md @@ -82,7 +82,7 @@ server <- function(input, output, session) { bindEvent(input$update) output$table <- renderTable(summary_tbl()) - output$code <- renderText(repro(summary_tbl)) + output$code <- renderText(reprex_reactivesummary_tbl)) } shinyApp(ui, server) diff --git a/man/repro.Rd b/man/repro.Rd index f72e81e..3f6ce6f 100644 --- a/man/repro.Rd +++ b/man/repro.Rd @@ -66,7 +66,7 @@ server <- function(input, output, session) { }) output$table <- renderTable(summary_tbl()) - output$code <- renderText(repro(summary_tbl)) + output$code <- renderText(reprex_reactivesummary_tbl)) } if (interactive()) { diff --git a/tests/testthat/test-call_chunk_function.R b/tests/testthat/test-call_chunk_function.R index 4e045da..5cb973d 100644 --- a/tests/testthat/test-call_chunk_function.R +++ b/tests/testthat/test-call_chunk_function.R @@ -33,7 +33,7 @@ test_that("Able to extract inputs inside anonymous functions within a reactive e expr = { session$setInputs(min_width = 2.5, max_width = 10) - repro_code <- repro(max_area) + repro_code <- reprex_reactivemax_area) expect_identical( repro_code, paste( @@ -64,7 +64,7 @@ test_that("Able to extract inputs as arguments to anonymous functions within a r expr = { session$setInputs(min_width = 2.5, max_width = 10) - repro_code <- repro(max_area) + repro_code <- reprex_reactivemax_area) expect_identical( repro_code, paste( diff --git a/tests/testthat/test-call_chunk_if.R b/tests/testthat/test-call_chunk_if.R index 73c38ca..724a0b8 100644 --- a/tests/testthat/test-call_chunk_if.R +++ b/tests/testthat/test-call_chunk_if.R @@ -14,7 +14,7 @@ test_that("Able to extract the 'if' part of an if/else statement", { expr = { session$setInputs(min_width = 3.5) - repro_code <- repro(summary_tbl) + repro_code <- reprex_reactivesummary_tbl) expect_identical(repro_code, "iris[with(iris, Sepal.Width > 3.5), ]") } ) @@ -36,7 +36,7 @@ test_that("Able to extract the 'else' part of an if/else statement", { expr = { session$setInputs(min_width = 2.5) - repro_code <- repro(summary_tbl) + repro_code <- reprex_reactivesummary_tbl) expect_identical(repro_code, "iris[with(iris, Sepal.Width < 2.5), ]") } ) @@ -60,7 +60,7 @@ test_that("Able to extract the 'else if' part of an if/else statement", { expr = { session$setInputs(min_width = 2.5, species = "versicolor") - repro_code <- repro(summary_tbl) + repro_code <- reprex_reactivesummary_tbl) expect_identical(repro_code, "iris[with(iris, Species == \"versicolor\" & Sepal.Width > 2.5), ]") } ) @@ -84,7 +84,7 @@ test_that("Able to extract the 'else if' part of an if/else if/else statement", expr = { session$setInputs(min_width = 2.5, species = "setosa") - repro_code <- repro(summary_tbl) + repro_code <- reprex_reactivesummary_tbl) expect_identical(repro_code, "iris[with(iris, Sepal.Width < 2.5), ]") } ) diff --git a/tests/testthat/test-call_chunk_null.R b/tests/testthat/test-call_chunk_null.R index 3fec114..4446e4e 100644 --- a/tests/testthat/test-call_chunk_null.R +++ b/tests/testthat/test-call_chunk_null.R @@ -18,7 +18,7 @@ test_that("Able to extract a `NULL` variable", { expr = { session$setInputs(min_width = 3.5) - repro_code <- repro(summary_tbl) + repro_code <- reprex_reactivesummary_tbl) expect_identical(repro_code, "datasets::penguins") } ) diff --git a/tests/testthat/test-chunk_reactive.R b/tests/testthat/test-chunk_reactive.R index 4161830..49369ee 100644 --- a/tests/testthat/test-chunk_reactive.R +++ b/tests/testthat/test-chunk_reactive.R @@ -54,7 +54,7 @@ test_that("Able to extract reactive expression code from a standard reactive", { expr = { session$setInputs(min_width = 3.5, summary_fn = "median") - repro_code <- repro(summary_tbl) + repro_code <- reprex_reactivesummary_tbl) expect_identical( repro_code, paste( @@ -88,7 +88,7 @@ test_that("Able to extract reactive expression code from bindCache", { expr = { session$setInputs(min_width = 3.5, summary_fn = "median") - repro_code <- repro(summary_tbl) + repro_code <- reprex_reactivesummary_tbl) expect_identical( repro_code, paste( @@ -122,7 +122,7 @@ test_that("Able to extract reactive expression code from bindEvent", { expr = { session$setInputs(min_width = 3.5, summary_fn = "median") - repro_code <- repro(summary_tbl) + repro_code <- reprex_reactivesummary_tbl) expect_identical( repro_code, paste( @@ -158,7 +158,7 @@ test_that("Able to extract reactive expression code from bindEvent and bindCache expr = { session$setInputs(min_width = 3.5, summary_fn = "median") - repro_code <- repro(summary_tbl) + repro_code <- reprex_reactivesummary_tbl) expect_identical( repro_code, paste( @@ -192,7 +192,7 @@ test_that("Able to extract reactive expression code from eventReactive", { expr = { session$setInputs(min_width = 3.5, summary_fn = "median") - repro_code <- repro(summary_tbl) + repro_code <- reprex_reactivesummary_tbl) expect_identical( repro_code, paste( diff --git a/tests/testthat/test-repro.R b/tests/testthat/test-repro.R index c7d097b..b6ca143 100644 --- a/tests/testthat/test-repro.R +++ b/tests/testthat/test-repro.R @@ -7,7 +7,7 @@ test_that("When a non-reactive call is passed to repro, error gets returned", { test_server, expr = { expect_error( - repro(iris), + reprex_reactiveiris), "Unable to generate reproducible code for iris, must be an unevaluated reactive object", fixed = TRUE ) @@ -24,7 +24,7 @@ test_that("When a reactive is evaluated into repro, specific error is returned t test_server, expr = { expect_error( - repro(test_reactive()), + reprex_reactivetest_reactive()), "test_reactive has already been evaluated, please remove brackets to pass through reactive object", fixed = TRUE ) @@ -40,12 +40,12 @@ test_that("Able to reproduce a simple one-line reactive", { shiny::testServer( test_server, expr = { - repro_code <- repro(test_reactive) + repro_code <- reprex_reactivetest_reactive) expect_identical(repro_code, "") session$setInputs(foo = "bar") - repro_code <- repro(test_reactive) + repro_code <- reprex_reactivetest_reactive) expect_identical(repro_code, "\"bar\"") } ) @@ -69,7 +69,7 @@ test_that("Able to reproduce a reactive stemming from another reactive", { expr = { session$setInputs(min_width = 3.5, summary_fn = "median") - repro_code <- repro(summary_tbl) + repro_code <- reprex_reactivesummary_tbl) expect_identical( repro_code, paste( @@ -108,7 +108,7 @@ test_that("When one non-standard package is used, it is added to the top of the expr = { session$setInputs(min_width = 3.5, summary_fn = "median") - repro_code <- repro(summary_tbl) + repro_code <- reprex_reactivesummary_tbl) expect_identical( repro_code, paste( @@ -157,7 +157,7 @@ test_that("Able to reproduce a reactive using the session user data", { expr = { session$setInputs(summary_fn = "median") - repro_code <- repro(summary_tbl) + repro_code <- reprex_reactivesummary_tbl) expect_identical( repro_code, paste( @@ -187,7 +187,7 @@ test_that("Able to reproduce a reactive without printing the environment variabl shiny::testServer( test_server, expr = { - repro_code <- repro(summary_tbl) + repro_code <- reprex_reactivesummary_tbl) expect_identical( repro_code, paste( @@ -222,7 +222,7 @@ test_that("Able to reproduce a complex reactive without printing the environment shiny::testServer( test_server, expr = { - repro_code <- repro(summary_tbl) + repro_code <- reprex_reactivesummary_tbl) expect_identical( repro_code, paste( @@ -255,7 +255,7 @@ test_that("Able to reproduce a reactive without printing the environment variabl expr = { session$setInputs(summary_fn = "median") - repro_code <- repro(summary_tbl) + repro_code <- reprex_reactivesummary_tbl) expect_identical( repro_code, "aggregate(Sepal.Width ~ Species, data = iris, FUN = get(Sys.getenv(\"DUMMY_FN\")))" @@ -280,10 +280,10 @@ test_that("When reproducing a reactive with multiple dependency reactives, simil nrow(reactive_1()) * nrow(reactive_2()) }) - repro_r1 <- shiny::isolate(repro(reactive_1)) + repro_r1 <- shiny::isolate(reprex_reactivereactive_1)) expect_no_match(repro_r1, "min_value <- 6") - repro_r3 <- shiny::isolate(repro(reactive_3)) + repro_r3 <- shiny::isolate(reprex_reactivereactive_3)) expect_match(repro_r3, "min_value <- 6") remove(min_value, reactive_1, reactive_2, reactive_3) @@ -297,7 +297,7 @@ test_that("When a reactive feeds is bound by an event, the repro only updates wh my_name <- reactive(input$name) |> bindEvent(input$button, ignoreInit = TRUE) - test_reactive <- reactive(repro(my_name)) |> + test_reactive <- reactive(reprex_reactivemy_name)) |> bindEvent(my_name()) } diff --git a/vignettes/shinyrepro.Rmd b/vignettes/shinyrepro.Rmd index babdf49..a414c38 100644 --- a/vignettes/shinyrepro.Rmd +++ b/vignettes/shinyrepro.Rmd @@ -38,11 +38,11 @@ width_range <- reactive({ }) # Good -repro_range <- reactive(repro(width_range)) |> +repro_range <- reactive(reprex_reactivewidth_range)) |> bindEvent(width_range()) # Bad -repro_range <- reactive(repro(width_range)) +repro_range <- reactive(reprex_reactivewidth_range)) ``` ### Put Side-Effects in Observers From 4a5109149f910ff173196171ecefed6c8bb3b2fe Mon Sep 17 00:00:00 2001 From: Ashley Baldry Date: Thu, 5 Feb 2026 10:39:31 +0000 Subject: [PATCH 3/4] Fix missing brackets from reprex_reactive --- DESCRIPTION | 4 +-- NAMESPACE | 2 +- R/{repro.R => reprex_reactive.R} | 4 +-- README.md | 2 +- man/{repro.Rd => reprex_reactive.Rd} | 10 +++---- tests/testthat/test-call_chunk_function.R | 4 +-- tests/testthat/test-call_chunk_if.R | 8 +++--- tests/testthat/test-call_chunk_null.R | 2 +- tests/testthat/test-chunk_reactive.R | 10 +++---- .../{test-repro.R => test-reprex_reactive.R} | 26 +++++++++---------- vignettes/shinyrepro.Rmd | 4 +-- 11 files changed, 38 insertions(+), 38 deletions(-) rename R/{repro.R => reprex_reactive.R} (95%) rename man/{repro.Rd => reprex_reactive.Rd} (89%) rename tests/testthat/{test-repro.R => test-reprex_reactive.R} (92%) diff --git a/DESCRIPTION b/DESCRIPTION index 7d750bc..244a7c6 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -8,7 +8,7 @@ Description: Provides functionality to extract reactive expressions from a 'Shin outside the interactive UI, facilitating integration into static reports or automated workflows without requiring access to the original application source code. License: MIT + file LICENSE -URL: https://github.com/AscentSoftware/shinyreprex, https://ascentsoftware.github.io/shinyrepro/ +URL: https://github.com/AscentSoftware/shinyreprex, https://ascentsoftware.github.io/shinyreprex/ BugReports: https://github.com/AscentSoftware/shinyreprex/issues Depends: R (>= 4.3.0) @@ -49,4 +49,4 @@ Collate: 'chunk_generic.R' 'chunk_reactive.R' 'package.R' - 'repro.R' + 'reprex_reactive.R' diff --git a/NAMESPACE b/NAMESPACE index 552b118..a512494 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,6 +1,6 @@ # Generated by roxygen2: do not edit by hand -export(repro) +export(reprex_reactive) if (getRversion() < "4.3.0") importFrom("S7", "@") importFrom(purrr,map) importFrom(styler,style_text) diff --git a/R/repro.R b/R/reprex_reactive.R similarity index 95% rename from R/repro.R rename to R/reprex_reactive.R index c95fc1a..ed32e79 100644 --- a/R/repro.R +++ b/R/reprex_reactive.R @@ -59,7 +59,7 @@ #' }) #' #' output$table <- renderTable(summary_tbl()) -#' output$code <- renderText(reprex_reactivesummary_tbl)) +#' output$code <- renderText(reprex_reactive(summary_tbl)) #' } #' #' if (interactive()) { @@ -67,7 +67,7 @@ #' } #' #' @export -repro <- function(x) { +reprex_reactive <- function(x) { if (!inherits(x, "reactiveExpr")) { x_name <- rlang::caller_arg(x) diff --git a/README.md b/README.md index 4310b9c..e0de05a 100644 --- a/README.md +++ b/README.md @@ -82,7 +82,7 @@ server <- function(input, output, session) { bindEvent(input$update) output$table <- renderTable(summary_tbl()) - output$code <- renderText(reprex_reactivesummary_tbl)) + output$code <- renderText(reprex_reactive(summary_tbl)) } shinyApp(ui, server) diff --git a/man/repro.Rd b/man/reprex_reactive.Rd similarity index 89% rename from man/repro.Rd rename to man/reprex_reactive.Rd index 3f6ce6f..f27515c 100644 --- a/man/repro.Rd +++ b/man/reprex_reactive.Rd @@ -1,10 +1,10 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/repro.R -\name{repro} -\alias{repro} +% Please edit documentation in R/reprex_reactive.R +\name{reprex_reactive} +\alias{reprex_reactive} \title{Reproduce Code} \usage{ -repro(x) +reprex_reactive(x) } \arguments{ \item{x}{\code{shiny::reactive} object to make reproducible} @@ -66,7 +66,7 @@ server <- function(input, output, session) { }) output$table <- renderTable(summary_tbl()) - output$code <- renderText(reprex_reactivesummary_tbl)) + output$code <- renderText(reprex_reactive(summary_tbl)) } if (interactive()) { diff --git a/tests/testthat/test-call_chunk_function.R b/tests/testthat/test-call_chunk_function.R index 5cb973d..b8658e6 100644 --- a/tests/testthat/test-call_chunk_function.R +++ b/tests/testthat/test-call_chunk_function.R @@ -33,7 +33,7 @@ test_that("Able to extract inputs inside anonymous functions within a reactive e expr = { session$setInputs(min_width = 2.5, max_width = 10) - repro_code <- reprex_reactivemax_area) + repro_code <- reprex_reactive(max_area) expect_identical( repro_code, paste( @@ -64,7 +64,7 @@ test_that("Able to extract inputs as arguments to anonymous functions within a r expr = { session$setInputs(min_width = 2.5, max_width = 10) - repro_code <- reprex_reactivemax_area) + repro_code <- reprex_reactive(max_area) expect_identical( repro_code, paste( diff --git a/tests/testthat/test-call_chunk_if.R b/tests/testthat/test-call_chunk_if.R index 724a0b8..f39d7f0 100644 --- a/tests/testthat/test-call_chunk_if.R +++ b/tests/testthat/test-call_chunk_if.R @@ -14,7 +14,7 @@ test_that("Able to extract the 'if' part of an if/else statement", { expr = { session$setInputs(min_width = 3.5) - repro_code <- reprex_reactivesummary_tbl) + repro_code <- reprex_reactive(summary_tbl) expect_identical(repro_code, "iris[with(iris, Sepal.Width > 3.5), ]") } ) @@ -36,7 +36,7 @@ test_that("Able to extract the 'else' part of an if/else statement", { expr = { session$setInputs(min_width = 2.5) - repro_code <- reprex_reactivesummary_tbl) + repro_code <- reprex_reactive(summary_tbl) expect_identical(repro_code, "iris[with(iris, Sepal.Width < 2.5), ]") } ) @@ -60,7 +60,7 @@ test_that("Able to extract the 'else if' part of an if/else statement", { expr = { session$setInputs(min_width = 2.5, species = "versicolor") - repro_code <- reprex_reactivesummary_tbl) + repro_code <- reprex_reactive(summary_tbl) expect_identical(repro_code, "iris[with(iris, Species == \"versicolor\" & Sepal.Width > 2.5), ]") } ) @@ -84,7 +84,7 @@ test_that("Able to extract the 'else if' part of an if/else if/else statement", expr = { session$setInputs(min_width = 2.5, species = "setosa") - repro_code <- reprex_reactivesummary_tbl) + repro_code <- reprex_reactive(summary_tbl) expect_identical(repro_code, "iris[with(iris, Sepal.Width < 2.5), ]") } ) diff --git a/tests/testthat/test-call_chunk_null.R b/tests/testthat/test-call_chunk_null.R index 4446e4e..5e7ed1c 100644 --- a/tests/testthat/test-call_chunk_null.R +++ b/tests/testthat/test-call_chunk_null.R @@ -18,7 +18,7 @@ test_that("Able to extract a `NULL` variable", { expr = { session$setInputs(min_width = 3.5) - repro_code <- reprex_reactivesummary_tbl) + repro_code <- reprex_reactive(summary_tbl) expect_identical(repro_code, "datasets::penguins") } ) diff --git a/tests/testthat/test-chunk_reactive.R b/tests/testthat/test-chunk_reactive.R index 49369ee..b067e77 100644 --- a/tests/testthat/test-chunk_reactive.R +++ b/tests/testthat/test-chunk_reactive.R @@ -54,7 +54,7 @@ test_that("Able to extract reactive expression code from a standard reactive", { expr = { session$setInputs(min_width = 3.5, summary_fn = "median") - repro_code <- reprex_reactivesummary_tbl) + repro_code <- reprex_reactive(summary_tbl) expect_identical( repro_code, paste( @@ -88,7 +88,7 @@ test_that("Able to extract reactive expression code from bindCache", { expr = { session$setInputs(min_width = 3.5, summary_fn = "median") - repro_code <- reprex_reactivesummary_tbl) + repro_code <- reprex_reactive(summary_tbl) expect_identical( repro_code, paste( @@ -122,7 +122,7 @@ test_that("Able to extract reactive expression code from bindEvent", { expr = { session$setInputs(min_width = 3.5, summary_fn = "median") - repro_code <- reprex_reactivesummary_tbl) + repro_code <- reprex_reactive(summary_tbl) expect_identical( repro_code, paste( @@ -158,7 +158,7 @@ test_that("Able to extract reactive expression code from bindEvent and bindCache expr = { session$setInputs(min_width = 3.5, summary_fn = "median") - repro_code <- reprex_reactivesummary_tbl) + repro_code <- reprex_reactive(summary_tbl) expect_identical( repro_code, paste( @@ -192,7 +192,7 @@ test_that("Able to extract reactive expression code from eventReactive", { expr = { session$setInputs(min_width = 3.5, summary_fn = "median") - repro_code <- reprex_reactivesummary_tbl) + repro_code <- reprex_reactive(summary_tbl) expect_identical( repro_code, paste( diff --git a/tests/testthat/test-repro.R b/tests/testthat/test-reprex_reactive.R similarity index 92% rename from tests/testthat/test-repro.R rename to tests/testthat/test-reprex_reactive.R index b6ca143..a26c355 100644 --- a/tests/testthat/test-repro.R +++ b/tests/testthat/test-reprex_reactive.R @@ -7,7 +7,7 @@ test_that("When a non-reactive call is passed to repro, error gets returned", { test_server, expr = { expect_error( - reprex_reactiveiris), + reprex_reactive(iris), "Unable to generate reproducible code for iris, must be an unevaluated reactive object", fixed = TRUE ) @@ -24,7 +24,7 @@ test_that("When a reactive is evaluated into repro, specific error is returned t test_server, expr = { expect_error( - reprex_reactivetest_reactive()), + reprex_reactive(test_reactive()), "test_reactive has already been evaluated, please remove brackets to pass through reactive object", fixed = TRUE ) @@ -40,12 +40,12 @@ test_that("Able to reproduce a simple one-line reactive", { shiny::testServer( test_server, expr = { - repro_code <- reprex_reactivetest_reactive) + repro_code <- reprex_reactive(test_reactive) expect_identical(repro_code, "") session$setInputs(foo = "bar") - repro_code <- reprex_reactivetest_reactive) + repro_code <- reprex_reactive(test_reactive) expect_identical(repro_code, "\"bar\"") } ) @@ -69,7 +69,7 @@ test_that("Able to reproduce a reactive stemming from another reactive", { expr = { session$setInputs(min_width = 3.5, summary_fn = "median") - repro_code <- reprex_reactivesummary_tbl) + repro_code <- reprex_reactive(summary_tbl) expect_identical( repro_code, paste( @@ -108,7 +108,7 @@ test_that("When one non-standard package is used, it is added to the top of the expr = { session$setInputs(min_width = 3.5, summary_fn = "median") - repro_code <- reprex_reactivesummary_tbl) + repro_code <- reprex_reactive(summary_tbl) expect_identical( repro_code, paste( @@ -157,7 +157,7 @@ test_that("Able to reproduce a reactive using the session user data", { expr = { session$setInputs(summary_fn = "median") - repro_code <- reprex_reactivesummary_tbl) + repro_code <- reprex_reactive(summary_tbl) expect_identical( repro_code, paste( @@ -187,7 +187,7 @@ test_that("Able to reproduce a reactive without printing the environment variabl shiny::testServer( test_server, expr = { - repro_code <- reprex_reactivesummary_tbl) + repro_code <- reprex_reactive(summary_tbl) expect_identical( repro_code, paste( @@ -222,7 +222,7 @@ test_that("Able to reproduce a complex reactive without printing the environment shiny::testServer( test_server, expr = { - repro_code <- reprex_reactivesummary_tbl) + repro_code <- reprex_reactive(summary_tbl) expect_identical( repro_code, paste( @@ -255,7 +255,7 @@ test_that("Able to reproduce a reactive without printing the environment variabl expr = { session$setInputs(summary_fn = "median") - repro_code <- reprex_reactivesummary_tbl) + repro_code <- reprex_reactive(summary_tbl) expect_identical( repro_code, "aggregate(Sepal.Width ~ Species, data = iris, FUN = get(Sys.getenv(\"DUMMY_FN\")))" @@ -280,10 +280,10 @@ test_that("When reproducing a reactive with multiple dependency reactives, simil nrow(reactive_1()) * nrow(reactive_2()) }) - repro_r1 <- shiny::isolate(reprex_reactivereactive_1)) + repro_r1 <- shiny::isolate(reprex_reactive(reactive_1)) expect_no_match(repro_r1, "min_value <- 6") - repro_r3 <- shiny::isolate(reprex_reactivereactive_3)) + repro_r3 <- shiny::isolate(reprex_reactive(reactive_3)) expect_match(repro_r3, "min_value <- 6") remove(min_value, reactive_1, reactive_2, reactive_3) @@ -297,7 +297,7 @@ test_that("When a reactive feeds is bound by an event, the repro only updates wh my_name <- reactive(input$name) |> bindEvent(input$button, ignoreInit = TRUE) - test_reactive <- reactive(reprex_reactivemy_name)) |> + test_reactive <- reactive(reprex_reactive(my_name)) |> bindEvent(my_name()) } diff --git a/vignettes/shinyrepro.Rmd b/vignettes/shinyrepro.Rmd index a414c38..189c3bc 100644 --- a/vignettes/shinyrepro.Rmd +++ b/vignettes/shinyrepro.Rmd @@ -38,11 +38,11 @@ width_range <- reactive({ }) # Good -repro_range <- reactive(reprex_reactivewidth_range)) |> +repro_range <- reactive(reprex_reactive(width_range)) |> bindEvent(width_range()) # Bad -repro_range <- reactive(reprex_reactivewidth_range)) +repro_range <- reactive(reprex_reactive(width_range)) ``` ### Put Side-Effects in Observers From 51c423f03e23a0efe57430859afbf1d3f90a2764 Mon Sep 17 00:00:00 2001 From: Ashley Baldry Date: Thu, 5 Feb 2026 11:00:15 +0000 Subject: [PATCH 4/4] Ensure that "repro" is updated where mentioned in docs --- R/chunk_reactive.R | 4 ++-- R/repro_call_chunk.R | 8 +++++--- R/repro_chunk.R | 5 +++-- README.md | 6 +++--- man/repro_chunk.Rd | 5 +++-- tests/testthat/test-call_chunk_null.R | 2 +- tests/testthat/test-chunk_reactive.R | 2 +- tests/testthat/test-reprex_reactive.R | 6 +++--- vignettes/shinyrepro.Rmd | 6 +++--- 9 files changed, 24 insertions(+), 20 deletions(-) diff --git a/R/chunk_reactive.R b/R/chunk_reactive.R index 16fd306..4324b45 100644 --- a/R/chunk_reactive.R +++ b/R/chunk_reactive.R @@ -1,8 +1,8 @@ #' @description #' When reproducing a reactive object, a step is required to get the environment that -#' the reactive was assigned in, rather than the environment that is calling `repro`. +#' the reactive was assigned in, rather than the environment that is calling `shiny_reprex`. #' For that, some diving into the internals of the observable object is required to -#' get the specific environment, before generating the repro code. +#' get the specific environment, before generating the reproducible code. #' #' ## Environments #' The `Observable` object attached to the given reactive is extracted. Within the diff --git a/R/repro_call_chunk.R b/R/repro_call_chunk.R index dfdbcb5..2a8e1e5 100644 --- a/R/repro_call_chunk.R +++ b/R/repro_call_chunk.R @@ -4,12 +4,14 @@ #' A short description... #' #' @param x `call` object to make reproducible, with prefixed class of the call name -#' @param env The environment `x` is defined in. By default it is the environment of where `repro` is called +#' @param env The environment `x` is defined in. By default it is the environment of where +#' `reprex_reactive` is called #' @param ... Additional arguments to pass to other methods #' #' @details -#' Whilst a default is provided to `env`, it is unlikely that this is the same environment `x` is defined -#' in. This is more of a placeholder for sending the correct environment to +#' Whilst a default is provided to `env`, it is unlikely that this is the same environment +#' `x` is defined in. This is more of a placeholder for sending the correct environment to +#' evaluate any reactive mentioned in the call. #' #' @returns #' A `Repro` object containing all the necessary code and packages to recreate diff --git a/R/repro_chunk.R b/R/repro_chunk.R index 57bc7ec..aa6b9f0 100644 --- a/R/repro_chunk.R +++ b/R/repro_chunk.R @@ -10,11 +10,12 @@ #' empty, but if `x` is not the first call within an expression, this will have #' prior calls and pre-requisites that might be used in `x`. #' @param env The environment `x` is defined in. By default it is the environment of where -#' `repro` is called +#' `reprex_reactive` is called #' #' @details #' Whilst a default is provided to `env`, it is unlikely that this is the same environment -#' `x` is defined in. This allows the top-level `repro` call +#' `x` is defined in. This allows the top-level `reprex_reactive` call to pass through +#' environments found for calls to other reactives in the chunk. #' #' @returns #' A `Repro` object containing all the necessary code and packages to recreate diff --git a/README.md b/README.md index e0de05a..69ba3ce 100644 --- a/README.md +++ b/README.md @@ -25,9 +25,9 @@ remotes::install_github("AscentSoftware/shinyreprex") ## Usage -The following examples takes a couple of inputs, and uses one of them in one reactive, and the other -in another reactive. The second reactive is a table output, which can be passed to `repro` to re-create -the code that generates the table seen in the UI. +The following examples takes a couple of inputs, and uses one of them in one reactive, and the +other in another reactive. The second reactive is a table output, which can be passed to +`reprex_reactive` to re-create the code that generates the table seen in the UI. ```r library(shiny) diff --git a/man/repro_chunk.Rd b/man/repro_chunk.Rd index 67da9a1..aa80a18 100644 --- a/man/repro_chunk.Rd +++ b/man/repro_chunk.Rd @@ -14,7 +14,7 @@ empty, but if \code{x} is not the first call within an expression, this will hav prior calls and pre-requisites that might be used in \code{x}.} \item{env}{The environment \code{x} is defined in. By default it is the environment of where -\code{repro} is called} +\code{reprex_reactive} is called} } \value{ A \code{Repro} object containing all the necessary code and packages to recreate @@ -27,6 +27,7 @@ them. } \details{ Whilst a default is provided to \code{env}, it is unlikely that this is the same environment -\code{x} is defined in. This allows the top-level \code{repro} call +\code{x} is defined in. This allows the top-level \code{reprex_reactive} call to pass through +environments found for calls to other reactives in the chunk. } \keyword{internal} diff --git a/tests/testthat/test-call_chunk_null.R b/tests/testthat/test-call_chunk_null.R index 5e7ed1c..abf1607 100644 --- a/tests/testthat/test-call_chunk_null.R +++ b/tests/testthat/test-call_chunk_null.R @@ -1,4 +1,4 @@ -test_that("When NULL value is parsed from a call, it returns the call in a repro object", { +test_that("When NULL value is parsed from a call, it returns the call in a Repro object", { null_call <- str2lang("datasets::penguins") class(null_call) <- c("NULL", class(null_call)) diff --git a/tests/testthat/test-chunk_reactive.R b/tests/testthat/test-chunk_reactive.R index b067e77..f7a88f5 100644 --- a/tests/testthat/test-chunk_reactive.R +++ b/tests/testthat/test-chunk_reactive.R @@ -35,7 +35,7 @@ test_that("Reactive code chunk is correctly extracted", { ) }) -# repro reactives ---- +# reprex reactives ---- test_that("Able to extract reactive expression code from a standard reactive", { test_server <- function(input, output, session) { iris_filt <- reactive(iris[with(iris, Sepal.Width > input$min_width), ]) diff --git a/tests/testthat/test-reprex_reactive.R b/tests/testthat/test-reprex_reactive.R index a26c355..db8a5c2 100644 --- a/tests/testthat/test-reprex_reactive.R +++ b/tests/testthat/test-reprex_reactive.R @@ -1,4 +1,4 @@ -test_that("When a non-reactive call is passed to repro, error gets returned", { +test_that("When a non-reactive call is passed to reprex_reactive, error gets returned", { test_server <- function(input, output, session) { test_reactive <- reactive(input$foo) } @@ -15,7 +15,7 @@ test_that("When a non-reactive call is passed to repro, error gets returned", { ) }) -test_that("When a reactive is evaluated into repro, specific error is returned to user", { +test_that("When a reactive is evaluated into reprex_reactive, specific error is returned to user", { test_server <- function(input, output, session) { test_reactive <- reactive(input$foo) } @@ -292,7 +292,7 @@ test_that("When reproducing a reactive with multiple dependency reactives, simil expect_identical(nrow(reactive_1) * nrow(reactive_2), 64L * 21L) }) -test_that("When a reactive feeds is bound by an event, the repro only updates when the reactive updates", { +test_that("When a reactive feeds is bound by an event, the reprex only updates when the reactive updates", { test_server <- function(input, output, session) { my_name <- reactive(input$name) |> bindEvent(input$button, ignoreInit = TRUE) diff --git a/vignettes/shinyrepro.Rmd b/vignettes/shinyrepro.Rmd index 189c3bc..4c89a05 100644 --- a/vignettes/shinyrepro.Rmd +++ b/vignettes/shinyrepro.Rmd @@ -18,14 +18,14 @@ library(shinyreprex) ## Using shinyreprex -There is a single exported function, `repro`, that takes a reactive object and converts it -into a script that can be reused outside of the Shiny application to reproduce the result +There is a single exported function, `reprex_reactive``, that takes a reactive object and converts +it into a script that can be reused outside of the Shiny application to reproduce the result of the reactive. This can be sent to a simple `verbatimTextOutput` or something more UX friendly such as the `{highlighter}` package to display the script in the UI. ## Best Practices -### Bind `repro` call to Event +### Bind `reprex_reactive` call to Event The code to reproduce a given reactive will be updated whenever an input or reactive feeding into the provided reactive is updated, therefore it is recommended to have the reactive as