Skip to content
Merged
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
8 changes: 4 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Package: shinyrepro
Package: shinyreprex
Type: Package
Title: Reproducible Code for 'Shiny' Objects
Version: 0.1.0
Expand All @@ -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/shinyreprex/
BugReports: https://github.com/AscentSoftware/shinyreprex/issues
Depends:
R (>= 4.3.0)
Imports:
Expand Down Expand Up @@ -49,4 +49,4 @@ Collate:
'chunk_generic.R'
'chunk_reactive.R'
'package.R'
'repro.R'
'reprex_reactive.R'
2 changes: 1 addition & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
@@ -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)
4 changes: 2 additions & 2 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions R/chunk_reactive.R
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions R/repro.R → R/reprex_reactive.R
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,15 @@
#' })
#'
#' output$table <- renderTable(summary_tbl())
#' output$code <- renderText(repro(summary_tbl))
#' output$code <- renderText(reprex_reactive(summary_tbl))
#' }
#'
#' if (interactive()) {
#' shinyApp(ui, server)
#' }
#'
#' @export
repro <- function(x) {
reprex_reactive <- function(x) {
if (!inherits(x, "reactiveExpr")) {
x_name <- rlang::caller_arg(x)

Expand Down
8 changes: 5 additions & 3 deletions R/repro_call_chunk.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions R/repro_chunk.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# shinyrepro
# shinyreprex

<!-- badges: start -->
[![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)
<!-- badges: end -->

## 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.
Expand All @@ -16,22 +16,22 @@ 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

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)
library(shinyrepro)
library(shinyreprex)

ui <- fluidPage(
h1("Reproducible Code Example"),
Expand Down Expand Up @@ -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_reactive(summary_tbl))
}

shinyApp(ui, server)
Expand Down
2 changes: 1 addition & 1 deletion _pkgdown.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
url: https://ascentsoftware.github.io/shinyrepro/
url: https://ascentsoftware.github.io/shinyreprex/
template:
package: ascentdown
bootstrap: 5
10 changes: 5 additions & 5 deletions man/repro.Rd → man/reprex_reactive.Rd

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

5 changes: 3 additions & 2 deletions man/repro_chunk.Rd

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

4 changes: 2 additions & 2 deletions tests/testthat.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")
4 changes: 2 additions & 2 deletions tests/testthat/test-call_chunk_function.R
Original file line number Diff line number Diff line change
Expand Up @@ -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_reactive(max_area)
expect_identical(
repro_code,
paste(
Expand Down Expand Up @@ -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_reactive(max_area)
expect_identical(
repro_code,
paste(
Expand Down
8 changes: 4 additions & 4 deletions tests/testthat/test-call_chunk_if.R
Original file line number Diff line number Diff line change
Expand Up @@ -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_reactive(summary_tbl)
expect_identical(repro_code, "iris[with(iris, Sepal.Width > 3.5), ]")
}
)
Expand All @@ -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_reactive(summary_tbl)
expect_identical(repro_code, "iris[with(iris, Sepal.Width < 2.5), ]")
}
)
Expand All @@ -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_reactive(summary_tbl)
expect_identical(repro_code, "iris[with(iris, Species == \"versicolor\" & Sepal.Width > 2.5), ]")
}
)
Expand All @@ -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_reactive(summary_tbl)
expect_identical(repro_code, "iris[with(iris, Sepal.Width < 2.5), ]")
}
)
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-call_chunk_null.R
Original file line number Diff line number Diff line change
@@ -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))

Expand All @@ -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_reactive(summary_tbl)
expect_identical(repro_code, "datasets::penguins")
}
)
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-call_chunk_utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -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", {
Expand Down
12 changes: 6 additions & 6 deletions tests/testthat/test-chunk_reactive.R
Original file line number Diff line number Diff line change
Expand Up @@ -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), ])
Expand All @@ -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_reactive(summary_tbl)
expect_identical(
repro_code,
paste(
Expand Down Expand Up @@ -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_reactive(summary_tbl)
expect_identical(
repro_code,
paste(
Expand Down Expand Up @@ -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_reactive(summary_tbl)
expect_identical(
repro_code,
paste(
Expand Down Expand Up @@ -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_reactive(summary_tbl)
expect_identical(
repro_code,
paste(
Expand Down Expand Up @@ -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_reactive(summary_tbl)
expect_identical(
repro_code,
paste(
Expand Down
Loading