Skip to content
Open
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
37 changes: 0 additions & 37 deletions .Rbuildignore

This file was deleted.

21 changes: 9 additions & 12 deletions .github/shiny-workflows/website.R
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
# pkgdown copies everything in `pkgdown/assets/` to the site root
dir.create("pkgdown/assets", showWarnings = FALSE)
# copy readme files
# pkgdown copies files in pkgdown/assets/ to the site root.
setwd("pkg-r")
dir.create("pkgdown/assets/demo", recursive = TRUE, showWarnings = FALSE)
pkgload::load_all(".", helpers = FALSE)
sample_js <- readLines("inst/log-files/log-cranwhales.js", encoding = "UTF-8")
sample_json <- sub(";\\s*$", "", sub("^window\\.log = ", "", paste(sample_js, collapse = "\n")))
log <- structure(jsonlite::fromJSON(sample_json, simplifyVector = FALSE), version = "1")
stopifnot(
file.copy("readme-images/", "pkgdown/assets/", recursive = TRUE)
)
# copy demo files
stopifnot(
file.copy("inst/reactlog/", "pkgdown/assets/", recursive = TRUE)
)
# rename to 'demo'
stopifnot(
file.rename("pkgdown/assets/reactlog", "pkgdown/assets/demo")
file.copy("readme-images", "pkgdown/assets", recursive = TRUE, overwrite = TRUE),
file.copy(reactlog::reactlog_render(log), "pkgdown/assets/demo/reactlog.html", overwrite = TRUE)
)
7 changes: 7 additions & 0 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,14 @@ name: Package checks
jobs:
website:
uses: rstudio/shiny-workflows/.github/workflows/website.yaml@v1
with:
working-directory: pkg-r
routine:
uses: rstudio/shiny-workflows/.github/workflows/routine.yaml@v1
with:
working-directory: pkg-r
js-working-directory: .
R-CMD-check:
uses: rstudio/shiny-workflows/.github/workflows/R-CMD-check.yaml@v1
with:
working-directory: pkg-r
41 changes: 41 additions & 0 deletions .github/workflows/report-viewer.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Standalone report viewer

on:
pull_request:
push:
branches: [main]

permissions:
contents: read

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- uses: actions/setup-node@v5
with:
node-version: 22
- run: npm ci
- run: npm run build-report
- name: Check committed viewer bundles
run: git diff --exit-code -- pkg-r/inst/reactlog pkg-r/inst/report pkg-py/src/reactlog/assets
- uses: r-lib/actions/setup-r@v2
with:
use-public-rspm: true
- uses: r-lib/actions/setup-r-dependencies@v2
with:
working-directory: pkg-r
packages: local::.
dependencies: '"hard"'
- uses: astral-sh/setup-uv@v7
with:
python-version: "3.10"
- name: Build and test the installed wheel
working-directory: pkg-py
run: |
uv build
uv sync --locked --extra dev --no-install-project
uv pip install --no-deps dist/*.whl
uv run --no-sync playwright install --with-deps chromium
uv run --no-sync python -m pytest tests ../tests
12 changes: 9 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Meta
doc
inst/doc
pkg-r/inst/doc

# History files
.Rhistory
Expand All @@ -25,8 +25,8 @@ docs/
.Rproj.user/

# produced vignettes
vignettes/*.html
vignettes/*.pdf
pkg-r/vignettes/*.html
pkg-r/vignettes/*.pdf

# OAuth2 token, see https://github.com/hadley/httr/releases/tag/v0.3
.httr-oauth
Expand Down Expand Up @@ -58,3 +58,9 @@ _ignore
/.agents/skills/*
!/.agents/skills/memory-bank/
.playwright-mcp/

# Python package development
.venv/
__pycache__/
.pytest_cache/
pkg-py/dist/
18 changes: 9 additions & 9 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,26 @@ This file provides guidance to AI coding agents (Claude Code, etc.) when working

## What this is

`reactlog` is an R package that visualizes Shiny's reactive dependency graph. A small R side (`R/`) injects Shiny's recorded log into an HTML page; a TypeScript app (`srcts/`) replays it as a cytoscape graph.
Both packages embed the report under `viewer/`. R calls `reactlog_render()` for saved and live reports. Python uses `format_reactlog_html()`. After editing the shared template, CSS, or TypeScript, run `npm run build-report` and commit the generated assets in `pkg-r/inst/report/` and `pkg-py/src/reactlog/assets/`. Package installations require no Node runtime.

The built bundle `inst/reactlog/reactlogAsset/reactlog.js` (and its `.map`) **is committed**. CRAN and `R-CMD-check` never run Node. If you change anything in `srcts/`, rebuild and commit the bundle with your change (the shared `routine` CI job also runs `npm ci` + `npm run build` and pushes any bundle changes back to same-repo PRs).
The original Cytoscape viewer under `srcts/` has its own build and replay tests. Its committed assets live under `pkg-r/inst/reactlog/`.

## Commands

JavaScript (npm; Node 22 works):

```bash
npm ci # install; postinstall also runs the build
npm run build-only # esbuild -> inst/reactlog/reactlogAsset/reactlog.js (no type check)
npm run build-only # esbuild -> pkg-r/inst/reactlog/reactlogAsset/reactlog.js (no type check)
npm run typecheck # tsc for app code, then for tests (tsconfig.test.json); no output files
npm test # replay the sample logs in inst/log-files/ (node:test)
npm test # replay the sample logs in pkg-r/inst/log-files/ (node:test)
npm run build # eslint --fix + prettier on srcts, typecheck, test, then build
npm run watch # lint, then rebuild on change (no type check)
npm run lint -- srcts/foo.ts # eslint --fix + prettier on given files
npm run check-shiny-target # fail if tsc/esbuild target differs from rstudio/shiny (needs network)
```

R:
R (from `pkg-r/`):

```r
devtools::load_all()
Expand All @@ -34,7 +34,7 @@ devtools::document() # regenerate man/ and NAMESPA
devtools::check()
```

`npm ci` installs a git pre-commit hook (`pre-commit` + `lint-staged`, config in `package.json`). On commit it lints staged `R/*.R` with `devtools::lint()` (needs the `lintr` R package) and, for staged `srcts/**/*.ts`, runs lint, typecheck, and build, then `git add`s the rebuilt bundle.
`npm ci` installs a git pre-commit hook (`pre-commit` + `lint-staged`, config in `package.json`). On commit it lints staged `pkg-r/R/*.R` with `devtools::lint()` (needs the `lintr` R package) and, for staged `srcts/**/*.ts`, runs lint, typecheck, and build, then `git add`s the rebuilt bundle.

## Memory Bank

Expand All @@ -52,10 +52,10 @@ the `!/.agents/skills/<name>/` lines in `.gitignore` to match.

`memory-bank/architecture.md` explains how the R side, the HTML template, and
the JavaScript app connect, plus how to work on the JS without running Shiny.
Read it before working in `R/` or `srcts/`.
Read it before working in `pkg-r/R/` or `srcts/`.

## Conventions

- Source is TypeScript (`tsconfig.json`, `strict` on). Lint is eslint 10 + typescript-eslint + prettier 3 (`eslint.config.mjs`, `prettier.config.js`).
- Add a NEWS.md entry for user-facing changes (CONTRIBUTING.md).
- New top-level files need an entry in `.Rbuildignore`, or R CMD check will warn.
- Add a pkg-r/NEWS.md entry for user-facing changes (CONTRIBUTING.md).
- New development files under `pkg-r/` may need an entry in `pkg-r/.Rbuildignore`, or R CMD check will warn.
62 changes: 0 additions & 62 deletions R/renderReactLog.R

This file was deleted.

123 changes: 5 additions & 118 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,121 +1,8 @@
# reactlog <a href='https://rstudio.github.io/reactlog/'><img src='man/figures/logo.svg' align="right" style="height: 139px;" /></a>
# Reactlog

<!-- badges: start -->
[![R build status](https://github.com/rstudio/reactlog/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/rstudio/reactlog/actions)
[![CRAN version](http://www.r-pkg.org/badges/version/reactlog)](https://cran.r-project.org/package=reactlog)
[![reactlog downloads per month](http://cranlogs.r-pkg.org/badges/reactlog)](http://www.rpackages.io/package/reactlog)
[![DOI](https://zenodo.org/badge/137799634.svg)](https://zenodo.org/badge/latestdoi/137799634)
[![RStudio community](https://img.shields.io/badge/community-reactlog-blue?style=social&logo=rstudio&logoColor=75AADB)](https://community.rstudio.com/tags/c/shiny/8/reactlog)
<!-- badges: end -->
Reactlog shows how a Shiny application's reactive dependencies change as it runs.

<br><!-- space above image break only -->
<!-- [![Coverage status](https://codecov.io/gh/rstudio/reactlog/branch/main/graph/badge.svg)](https://codecov.io/github/rstudio/reactlog?branch=main) -->
* The [R package](pkg-r/) opens the reactive graph from a running Shiny app. [Try the demo](https://rstudio.github.io/reactlog/demo/reactlog.html).
* The [Python package](pkg-py/) turns a saved R or Python trace into an interactive HTML report.


<img src="http://rstudio.github.io/reactlog/readme-images/pythagoras.gif" style="border: 1px solid black; box-shadow: 5px 5px 5px #eee;" width="100%">

[Shiny](https://shiny.rstudio.com/) is an R package from RStudio that makes it incredibly easy to build interactive web applications with R. Behind the scenes, Shiny builds a reactive graph that can quickly become intertwined and difficult to debug. **reactlog** provides a visual insight into that _black box_ of Shiny reactivity.

After logging the reactive interactions of a Shiny application, **reactlog** constructs a directed dependency graph of the Shiny's reactive state at any time point in the record. The **reactlog** dependency graph provides users with the ability to visually see if reactive elements are:
* Not utilized (never retrieved)
* Over utilized (called independently many times)
* Interacting with unexpected elements
* Invalidating all expected dependencies
* Freezing (and thawing), preventing triggering of future reactivity

<!-- For an introduction and examples, visit the [Shiny Dev Center](https://shiny.rstudio.com/). -->


## Major Features

There are many subtle features hidden throughout **reactlog**. Here is a short list quickly describing what is possible within **reactlog**:

* Display the reactivity dependency graph of your Shiny applications
* Navigate throughout your reactive history to replay element interactions
* Highlight reactive family trees
* Filter on reactive family trees
* Search for reactive elements

For a more in-depth explanation of **reactlog**, please visit the [**reactlog** vignette](https://rstudio.github.io/reactlog/articles/reactlog.html).

## Installation

To install the stable version from CRAN, run the following from an R console:

```r
install.packages("reactlog")
```

For the latest development version:

```r
remotes::install_github("rstudio/reactlog")
```

## Usage


```r
library(shiny)
library(reactlog)

# tell shiny to log all reactivity
reactlog_enable()

# run a shiny app
app <- system.file("examples/01_hello", package = "shiny")
runApp(app)

# once app has closed, display reactlog from shiny
shiny::reactlogShow()
```

Or while your Shiny app is running, press the key combination `Ctrl+F3` (Mac: `Cmd+F3`) to launch the **reactlog** application.

To mark a specific execution time point within your Shiny app, press the key combination `Ctrl+Shift+F3` or `Ctrl+F4` (Mac: `Cmd+Shift+F3` or `Cmd+F4`). This will highlight a specific point in time in your reactlog.


#### Example

Here is a [demo](https://rstudio.github.io/reactlog/demo/reactlog.html) of the **reactlog** visualization applied to the [`cranwhales`](https://github.com/rstudio/cranwhales) shiny app.

[
<img src="http://rstudio.github.io/reactlog/readme-images/cranwhales.gif" style="border: 1px solid black; box-shadow: 5px 5px 5px #eee;" width="100%">
](https://rstudio.github.io/reactlog/demo/reactlog.html)

For more examples and explanation, see the [**reactlog** vignette](https://rstudio.github.io/reactlog/articles/reactlog.html#reactlog).


## Community Support

The best place to get help with Shiny and **reactlog** is [RStudio Community](https://community.rstudio.com/c/shiny/8).
If you're having difficulties with **reactlog**, feel free to [ask questions here](https://community.rstudio.com/new-topic?title=&category_id=8&tags=reactlog&body=%0A%0A%0A%20%20--------%0A%20%20%0A%20%20%3Csup%3EReferred%20here%20by%20%60reactlog%60%27s%20README%3C/sup%3E%0A&u=barret).
For bug reports, please use the **reactlog** [issue tracker](https://github.com/rstudio/reactlog/issues).


## Development

[![node version: 22.x](https://img.shields.io/badge/node-22.x-brightgreen.svg)](https://nodejs.org/en/)
[![language: TypeScript](https://img.shields.io/badge/language-TypeScript-3178c6.svg)](https://www.typescriptlang.org/)
[![cytoscape](https://img.shields.io/github/package-json/dependency-version/rstudio/reactlog/cytoscape.svg)](https://js.cytoscape.org/)
[![esbuild](https://img.shields.io/github/package-json/dependency-version/rstudio/reactlog/dev/esbuild.svg)](https://esbuild.github.io/)
[![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier)
[![linter: eslint](https://img.shields.io/badge/linter-eslint-3524ca.svg)](https://eslint.org/)


Please make sure you have [GitHub Large File Storage](https://git-lfs.github.com/) and [Node.js](https://nodejs.org/en/) installed.

Installation script:

```bash
# install git lfs hooks
git lfs install

# install dependencies and build JavaScript
npm install

# build on file change
npm run watch
```

By changing the file `'./inst/reactlog/defaultLog.js'` with the contents of any log file in `'./inst/log-files/'`, different default log files can be loaded. Once the local JavaScript (`'./inst/reactlog/reactlogAsset/reactlog.js'`) has been built with `npm run build` or `npm run watch`, refresh `'./inst/reactlog/reactlog.html'` to avoid constantly spawning Shiny applications for testing.
Both packages open the same interactive report. The timeline, graph, HTML, and styles live in `viewer/`. Run `npm ci` and `npm run build-report` at the repository root to build the viewer for both packages.
Loading
Loading