| Title: | Reproducible Code for 'Shiny' Objects |
|---|---|
| Description: | Provides functionality to extract reactive expressions from a 'shiny' application and convert them into stand-alone R scripts. This enables users to reproduce tables and visualisations outside the interactive UI, facilitating integration into static reports or automated workflows without requiring access to the original application source code. |
| Authors: | Ashley Baldry [aut, cre] |
| Maintainer: | Ashley Baldry <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.2.0 |
| Built: | 2026-06-29 15:01:38 UTC |
| Source: | https://github.com/cran/shinyreprex |
Construct the code within a given shiny::reactive object
to be able to re-create the output outside of a Shiny session.
reprex_reactive(x)reprex_reactive(x)
x |
|
A character string, that when printed (using base::cat),
displays the script that reproduces the contents of x.
library(shiny) ui <- fluidPage( h1("Reproducible Code Example"), inputPanel( sliderInput( "min_width", "Minimum Petal Width", min(iris$Petal.Width), max(iris$Petal.Width), min(iris$Petal.Width), step = 0.1 ), selectInput( "summary_fn", "Summary Function", c("Mean" = "mean", "Median" = "median", "SD" = "sd"), selected = "mean" ) ), fluidRow( column( width = 5, h2("Table"), tableOutput("table") ), column( width = 7, h2("Code"), verbatimTextOutput("code") ) ) ) server <- function(input, output, session) { iris_filt <- reactive({ iris[with(iris, Petal.Width > input$min_width), ] }) summary_tbl <- reactive({ aggregate( Sepal.Width ~ Species, data = iris_filt(), FUN = get(input$summary_fn) ) }) output$table <- renderTable(summary_tbl()) output$code <- renderText(reprex_reactive(summary_tbl)) } if (interactive()) { shinyApp(ui, server) }library(shiny) ui <- fluidPage( h1("Reproducible Code Example"), inputPanel( sliderInput( "min_width", "Minimum Petal Width", min(iris$Petal.Width), max(iris$Petal.Width), min(iris$Petal.Width), step = 0.1 ), selectInput( "summary_fn", "Summary Function", c("Mean" = "mean", "Median" = "median", "SD" = "sd"), selected = "mean" ) ), fluidRow( column( width = 5, h2("Table"), tableOutput("table") ), column( width = 7, h2("Code"), verbatimTextOutput("code") ) ) ) server <- function(input, output, session) { iris_filt <- reactive({ iris[with(iris, Petal.Width > input$min_width), ] }) summary_tbl <- reactive({ aggregate( Sepal.Width ~ Species, data = iris_filt(), FUN = get(input$summary_fn) ) }) output$table <- renderTable(summary_tbl()) output$code <- renderText(reprex_reactive(summary_tbl)) } if (interactive()) { shinyApp(ui, server) }