• Stars
    star
    220
  • Rank 176,298 (Top 4 %)
  • Language
    R
  • Created about 5 years ago
  • Updated about 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Record and expose Shiny app logic using metaprogramming

shinymeta

R build status CRAN status Lifecycle: experimental

The shinymeta R package provides tools for capturing logic in a Shiny app and exposing it as code that can be run outside of Shiny (e.g., from an R console). It also provides tools for bundling both the code and results to the end user.

Installation

Install the stable release of shinymeta on CRAN:

install.packages("shinymeta")

Or, install the development version with:

remotes::install_github("rstudio/shinymeta")

Generating code with shinymeta

In short, shinymeta provides counterparts to Shiny's reactive building blocks (e.g., reactive() -> metaReactive(), observe() -> metaObserve(), render() -> metaRender()) that have the added ability to capture and expose the logic needed to recreate their current state outside of the Shiny runtime. Once the appropriate logic has been captured by these meta-counterparts and reactive reads (e.g., input$var, var()) have been marked by a special ..() operator, then expandChain() can produce code to replicate the state of a particular meta-counterpart (e.g., output$Summary).

library(shiny)
library(shinymeta)

ui <- fluidPage(
  selectInput("var", label = "Choose a variable", choices = names(cars)),
  verbatimTextOutput("Summary"),
  verbatimTextOutput("code")
)

server <- function(input, output) {
  var <- metaReactive({
    cars[[..(input$var)]]
  })
  output$Summary <- metaRender(renderPrint, {
    summary(..(var()))
  })
  output$code <- renderPrint({
    expandChain(output$Summary())
  })
}

shinyApp(ui, server)

For more details, explanation, and overview shinymeta features, see the article on code generation as well as code distribution.

Breaking changes in shinymeta 0.2.0

On August 6, 2019, we introduced a major syntax change into shinymeta, that is not compatible with the previous syntax. If you're here after watching @jcheng5's useR2019 talk or reading @zappingseb's blog post, please be aware that the !! operator has been replaced with a ..() function. See this page for details.

A motivating example

Below is a screen-recording of a Shiny app which allows you to obtain CRAN download statistics for any combination of CRAN packages, look at those downloads using different aggregations, and produce a Rmd-based report with code to reproduce the visualization. This Shiny app is different from most in that it generates R code to reproduce what the user sees in the Shiny app (i.e., notice how the generated report reflects the user's input).

We hope this example helps illustrate and inspire several reasons why you might want to generate standalone R code that mimics logic in your Shiny app:

  • Automation: Shiny apps often use data that changes over time: stock quotes, sensor readings, centralized databases, etc. By providing users with reproducible R code, you enable them to take that logic into other workflows, such as creating a periodic R Markdown email using RStudio Connect (e.g., the R code generated by the Shiny app above has been tailored so that anyone can re-run the code to acquire the latest download statistics).

  • Transparency: By generating code that exposes the core logic of your shiny app, you make things more transparent for yourself and others, which has numerous benefits:

    • Reassurance: In the domain of data analysis, it's usually enough hard to know exactly how a result is derived, and be confident that it's 100% correct. Unfortunately, wrapping your analysis code in a user interface like Shiny make the situation even worse: the analysis code is now embedded inside a larger system making the overall logic even more error prone and difficult to fully understand. Export the core logic of your analysis can help reassure others (and yourself!) that your work is correct.

    • Education: For example, in the classroom, a student might use a Shiny app interactively to gain intuitive understanding of a statistical concept, then use the code to learn how to use the corresponding function from their own R scripts.

    • Enabling: Shiny is great for enabling others to interface with an R script you've written, but what if your users wish to explore things that your interface doesn't allow for? By exposing the core logic of your app, you make it easier for motivated users to modify and build upon your work in ways you never thought about.

    • Documentation: This one is especially relevant for exploratory analysis apps that allow you to derive insight from a dataset. A great example is the ANOVA example app, where you can upload a dataset, run an ANOVA analysis, then download a report with all ANOVA results as well as the code to reproduce it.

  • Permanence: Using a Shiny app can have an ephemeral feeling to it; what happens in the future if the server goes down, or the app's features change? With a reproducible report, your users can download a more permanent artifact that can be saved locally.

Acknowledgements

Many people projects provided motivation, inspiration, and ideas that have lead to shinymeta. Thanks especially to Adrian Waddell for inspiring the over-overarching metaprogramming approach and Doug Kelkhoff for his work on scriptgloss. Also thanks to Eric Nantz and Xiao Ni for providing feedback and insight on potential applications. We'd also like to acknowledge and highlight other work towards this same goal such as http://intro-stats.com (Eric Hare and Andee Kaplan) and https://radiant-rstats.github.io/docs/ (Vincent Nijs).

More Repositories

1

cheatsheets

Posit Cheat Sheets - Can also be found at https://posit.co/resources/cheatsheets/.
TeX
5,673
star
2

shiny

Easy interactive web applications with R
R
5,281
star
3

rstudio

RStudio is an integrated development environment (IDE) for R
Java
4,432
star
4

bookdown

Authoring Books and Technical Documents with R Markdown
JavaScript
3,690
star
5

rmarkdown

Dynamic Documents for R
R
2,737
star
6

shiny-examples

JavaScript
1,945
star
7

gt

Easily generate information-rich, publication-quality tables from R
R
1,934
star
8

blogdown

Create Blogs and Websites with R Markdown
R
1,710
star
9

reticulate

R Interface to Python
R
1,634
star
10

webinars

Code and slides for RStudio webinars
HTML
1,510
star
11

rticles

LaTeX Journal Article Templates for R Markdown
TeX
1,402
star
12

plumber

Turn your R code into a web API.
R
1,374
star
13

tensorflow

TensorFlow for R
R
1,322
star
14

renv

renv: Project environments for R.
R
975
star
15

pagedown

Paginate the HTML Output of R Markdown with CSS for Print
R
873
star
16

shinydashboard

Shiny Dashboarding framework
CSS
852
star
17

pointblank

Data quality assessment and metadata reporting for data frames and database tables
R
826
star
18

keras

R Interface to Keras
R
823
star
19

flexdashboard

Easy interactive dashboards for R
JavaScript
804
star
20

leaflet

R Interface to Leaflet Maps
JavaScript
793
star
21

rmarkdown-book

R Markdown: The Definitive Guide (published by Chapman & Hall/CRC in July 2018)
RMarkdown
738
star
22

ggvis

Interactive grammar of graphics for R
R
709
star
23

shiny-server

Host Shiny applications over the web.
JavaScript
707
star
24

learnr

Interactive Tutorials with R Markdown
R
704
star
25

rstudio-conf

Materials for rstudio::conf
HTML
699
star
26

RStartHere

A guide to some of the most useful R Packages that we know about
R
661
star
27

py-shiny

Shiny for Python
Python
627
star
28

DT

R Interface to the jQuery Plug-in DataTables
JavaScript
581
star
29

rmarkdown-cookbook

R Markdown Cookbook. A range of tips and tricks to make better use of R Markdown.
RMarkdown
568
star
30

blastula

Easily send great-looking HTML email messages from R
R
530
star
31

r2d3

R Interface to D3 Visualizations
R
514
star
32

bookdown-demo

A minimal book example using bookdown
CSS
476
star
33

bslib

Tools for theming Shiny and R Markdown via Bootstrap 3, 4, or 5.
SCSS
441
star
34

hex-stickers

RStudio hex stickers
R
434
star
35

distill

Distill for R Markdown
HTML
419
star
36

packrat

Packrat is a dependency management system for R
R
394
star
37

tufte

Tufte Styles for R Markdown Documents
R
385
star
38

dygraphs

R interface to dygraphs
JavaScript
361
star
39

revealjs

R Markdown Format for reveal.js Presentations
JavaScript
316
star
40

pins-r

Pin, Discover and Share Resources
R
301
star
41

fontawesome

Easily insert FontAwesome icons into R Markdown docs and Shiny apps
R
290
star
42

profvis

Visualize R profiling data
JavaScript
285
star
43

crosstalk

Inter-htmlwidget communication for R (with and without Shiny)
JavaScript
284
star
44

config

config package for R
R
247
star
45

tinytex-releases

Windows/macOS/Linux binaries and installation methods of TinyTeX
PowerShell
245
star
46

pool

Object Pooling in R
R
244
star
47

thematic

Theme ggplot2, lattice, and base graphics based on a few simple settings.
R
242
star
48

Intro

Course materials for "Introduction to Data Science with R", a video course by RStudio and O'Reilly Media
R
234
star
49

shinytest

Automated testing for shiny apps
JavaScript
224
star
50

nomnoml

Sassy 'UML' Diagrams for R
JavaScript
218
star
51

httpuv

HTTP and WebSocket server package for R
C
217
star
52

shinyuieditor

A GUI for laying out a Shiny application that generates clean and human-readable UI code
JavaScript
208
star
53

htmltools

Tools for HTML generation and output
R
201
star
54

promises

A promise library for R
R
195
star
55

vetiver-r

Version, share, deploy, and monitor models
R
176
star
56

rstudioapi

Safely access RStudio's API (when available)
R
161
star
57

gradethis

Tools for teachers to use with learnr
R
160
star
58

concept-maps

Concept maps for all things data science
HTML
158
star
59

master-the-tidyverse

Course contents for Master the Tidyverse
155
star
60

shinythemes

Themes for Shiny
R
152
star
61

ShinyDeveloperConference

Materials collected from the First Shiny Developer Conference Palo Alto, CA January 30-31 2016
HTML
152
star
62

chromote

Chrome Remote Interface for R
R
151
star
63

shiny-gallery

Code and other documentation for apps in the Shiny Gallery ✨
HTML
145
star
64

sortable

R htmlwidget for Sortable.js
R
124
star
65

reactlog

Shiny Reactivity Visualizer
JavaScript
121
star
66

rsconnect

Publish Shiny Applications, RMarkdown Documents, Jupyter Notebooks, Plumber APIs, and more
R
120
star
67

redx

dynamic nginx configuration
Lua
118
star
68

r-docker

Docker images for R
Dockerfile
117
star
69

bigdataclass

Two-day workshop that covers how to use R to interact databases and Spark
R
114
star
70

r-system-requirements

System requirements for R packages
Shell
111
star
71

shinyapps

Deploy Shiny applications to ShinyApps
110
star
72

webshot2

Take screenshots of web pages from R
R
109
star
73

shinyloadtest

Tools for load testing Shiny applications
HTML
108
star
74

shinyvalidate

Input validation package for the Shiny web framework
JavaScript
108
star
75

miniUI

R
102
star
76

sass

Sass compiler package for R
C++
102
star
77

shinytest2

R
100
star
78

keras-customer-churn

Customer Churn Shiny Application
R
99
star
79

r-builds

an opinionated environment for compiling R
Shell
92
star
80

r-manuals

A re-styled version of the R manuals
R
85
star
81

addinexamples

An R package showcasing how RStudio addins can be registered and used.
R
85
star
82

shinyapps-package-dependencies

Collection of bash scripts that install R package system dependencies
R
74
star
83

markdown

The first generation of Markdown rendering for R (born in 2012). Originally based on the C library sundown. Now based on commonmark. Note that this package is markdown, not *rmarkdown*.
R
72
star
84

R-Websockets

HTML 5 Websockets implementation for R
R
68
star
85

webdriver

WebDriver client in R
R
68
star
86

beyond-dashboard-fatigue

Materials for the RStudio webinar 'Beyond Dashboard Fatigue'
R
66
star
87

cloudml

R interface to Google Cloud Machine Learning Engine
R
65
star
88

rstudio-docker-products

Docker images for RStudio Professional Products
Shell
62
star
89

shinylive

Run Shiny on Python (compiled to wasm) in the browser
TypeScript
61
star
90

rstudio-conf-2022-program

rstudio::conf(2022, "program")
R
60
star
91

bookdown.org

Source documents to generate the bookdown.org website
R
59
star
92

vetiver-python

Version, share, deploy, and monitor models.
Python
58
star
93

education.rstudio.com

CSS
57
star
94

tfestimators

R interface to TensorFlow Estimators
R
57
star
95

connections

https://rstudio.github.io/connections/
R
54
star
96

tfprobability

R interface to TensorFlow Probability
R
54
star
97

sparkDemos

HTML
53
star
98

shiny-incubator

Examples and ideas that don't belong in the core Shiny package and aren't officially supported.
JavaScript
53
star
99

swagger

Swagger is a collection of HTML, Javascript, and CSS assets that dynamically generate beautiful documentation from a Swagger-compliant API.
HTML
51
star
100

leaflet.mapboxgl

Extends the R Leaflet package with a Mapbox GL JS plugin to allow easy drawing of vector tile layers.
R
49
star