| Title: | Manipulate 'JSON' Data in the Browser with a 'dplyr' Interface |
| Version: | 0.1.0 |
| Description: | A 'dplyr' backend for 'shiny' applications that manipulates 'JSON' data in the web browser instead of on the server. Data manipulation verbs such as filter, select, mutate, summarise, arrange, and joins are evaluated lazily and translated into 'JavaScript' operations that run client-side, following the lazy evaluation approach of 'dbplyr' but generating 'JavaScript' rather than 'SQL'. Results are returned to R asynchronously as promises. This keeps data wrangling responsive for large data frames by offloading the work to the client. |
| License: | MIT + file LICENSE |
| URL: | https://github.com/r-world-devs/jsplyr, https://r-world-devs.github.io/jsplyr/ |
| BugReports: | https://github.com/r-world-devs/jsplyr/issues |
| Encoding: | UTF-8 |
| Depends: | R (≥ 4.1.0) |
| Imports: | cli, dplyr, glue, htmltools, jsonlite, promises, purrr, rlang, shiny, stringr |
| Suggests: | knitr, rmarkdown, shinytest2, testthat (≥ 3.0.0) |
| VignetteBuilder: | knitr |
| Config/testthat/edition: | 3 |
| Config/roxygen2/version: | 8.0.0 |
| NeedsCompilation: | no |
| Packaged: | 2026-07-07 06:55:45 UTC; banas |
| Author: | Maciej Banas [cre, aut], Krystian Igras [aut] |
| Maintainer: | Maciej Banas <banasmaciek@gmail.com> |
| Repository: | CRAN |
| Date/Publication: | 2026-07-16 12:40:14 UTC |
Arrange rows of JSON data by column values.
Description
Arrange rows of JSON data by column values.
Usage
## S3 method for class 'tbl_lazy_json'
arrange(.data, ..., .by_group = FALSE)
Arguments
.data |
A |
... |
Columns to sort by. Wrap a column in |
.by_group |
Ignored. Accepted for consistency with the generic;
grouped arrange ordering is not applied for |
Details
Sorting happens in the browser and is stable across ties, so the original row order is preserved within equal keys.
Value
A tbl_lazy_json object with the sort appended as a lazy compute
step. The ordering is applied in the browser when the pipeline is
evaluated by compute()/collect().
Examples
if (interactive()) {
tbl(session, "mtcars") |>
arrange(cyl, desc(mpg))
}
Retrieve JSON data from the browser.
Description
Retrieve JSON data from the browser.
Usage
## S3 method for class 'tbl_lazy_json'
collect(x, ..., raw = FALSE)
Arguments
x |
A |
... |
Unused. Provided for consistency with generic. |
raw |
A logical, if |
Value
A promises::promise(). When raw = FALSE (the default) it resolves
to a tibble::tibble built from the computed JSON; when raw = TRUE it
resolves to the raw JSON string. The result is fetched asynchronously
from the browser, so the value is a promise rather than a data frame.
Compute JSON data in the browser.
Description
Compute JSON data in the browser.
Usage
## S3 method for class 'tbl_lazy_json'
compute(x, ...)
Arguments
x |
A |
... |
Unused. Provided for consistency with generic. |
Value
A tbl_lazy_json object with a pending computation attached. It
carries a .promise field holding a promises::promise() that resolves
when the browser posts back the computed JSON. The accumulated compute
steps are reset so the object can be extended or collected further.
Copy a local or remote data frame to the browser
Description
Copy a local or remote data frame to the browser
Usage
## S3 method for class 'ShinySession'
copy_to(dest, df, ...)
Arguments
dest |
A shiny |
df |
A local |
... |
Unused. Provided for consistency with generic. |
Value
Invisibly, a tbl_lazy_json object referencing the data now
registered in the browser, ready to be piped into the data manipulation
verbs. Called primarily for the side effect of sending the data to the
client.
Count observations in JSON data.
Description
count() groups the data by the given columns and counts the
rows in each group. tally() counts rows for the existing grouping set by
group_by() without adding new grouping columns. Both build on the
group_by()/summarise() machinery and run in the browser.
Usage
## S3 method for class 'tbl_lazy_json'
count(x, ..., wt = NULL, sort = FALSE, name = NULL)
## S3 method for class 'tbl_lazy_json'
tally(x, wt = NULL, sort = FALSE, name = NULL)
Arguments
x |
A |
... |
Columns to group by before counting (for |
wt |
Not supported; weighted counts are not implemented for
|
sort |
If |
name |
Name of the count column in the output. |
Value
A tbl_lazy_json object with the count appended as a lazy compute
step. When evaluated it yields one row per group with the count column
(named by name, default "n") added.
Examples
if (interactive()) {
tbl(session, "mtcars") |> count(cyl)
tbl(session, "mtcars") |> count(cyl, sort = TRUE)
tbl(session, "mtcars") |> group_by(cyl) |> tally()
}
Keep distinct records of JSON data.
Description
Keep distinct records of JSON data.
Usage
## S3 method for class 'tbl_lazy_json'
distinct(.data, ..., .keep_all = FALSE)
Arguments
.data |
A |
... |
Column names to determine uniqueness. If empty, all columns are used. |
.keep_all |
If |
Value
A tbl_lazy_json object with the de-duplication appended as a lazy
compute step, applied in the browser when the pipeline is evaluated.
Add filter to JSON data.
Description
Add filter to JSON data.
Usage
## S3 method for class 'tbl_lazy_json'
filter(.data, ...)
Arguments
.data |
A |
... |
Filtering expressions. Comparisons ( |
Value
A tbl_lazy_json object with the filter appended as a lazy compute
step. Rows are subset in the browser when the pipeline is evaluated by
compute()/collect().
Group JSON data by one or more columns.
Description
Group JSON data by one or more columns.
Usage
## S3 method for class 'tbl_lazy_json'
group_by(.data, ...)
Arguments
.data |
A |
... |
Columns to group by. Accepts bare column names as well as the
tidyselect helpers |
Value
A tbl_lazy_json object carrying the grouping as browser-side state.
The grouping is consumed by group-aware verbs such as summarise(),
count(), and the slice() family when the pipeline is evaluated.
Link JS code.
Description
Include the jsplyr JavaScript code in a Shiny app. To be put
in the UI part of the app.
Usage
include_jsplyr()
Value
An htmlDependency object.
Join two JSON tables.
Description
Mutating joins (left_join, right_join, inner_join,
full_join) combine columns from x and y, matching rows by key
columns. Filtering joins (semi_join, anti_join) keep columns from
x, using y only to determine which rows to keep.
Usage
## S3 method for class 'tbl_lazy_json'
left_join(x, y, by = NULL, ...)
## S3 method for class 'tbl_lazy_json'
right_join(x, y, by = NULL, ...)
## S3 method for class 'tbl_lazy_json'
inner_join(x, y, by = NULL, ...)
## S3 method for class 'tbl_lazy_json'
full_join(x, y, by = NULL, ...)
## S3 method for class 'tbl_lazy_json'
semi_join(x, y, by = NULL, ...)
## S3 method for class 'tbl_lazy_json'
anti_join(x, y, by = NULL, ...)
Arguments
x |
A |
y |
A |
by |
A character vector of columns to join by. Use a named vector
(e.g. |
... |
Unused. Provided for consistency with the generics. |
Value
A tbl_lazy_json object with the join appended as a compute step.
Add or modify columns in JSON data.
Description
Add or modify columns in JSON data.
Usage
## S3 method for class 'tbl_lazy_json'
mutate(.data, ...)
Arguments
.data |
A |
... |
Name-value pairs of expressions.
The name gives the name of the column in the output.
The value should be an expression using existing columns,
e.g. Conditional helpers are translated to JavaScript:
|
Value
A tbl_lazy_json object with the column additions/modifications
appended as a lazy compute step, evaluated in the browser when the pipeline
is computed.
Promise pipe operators
Description
collect() on a tbl_lazy_json returns a promises::promise(), because the
result is fetched asynchronously from the browser. These operators from the
promises package are re-exported so you can consume that result inside
shiny::observeEvent() / shiny::observe() without attaching promises
yourself.
Usage
lhs %...>% rhs
lhs %...!% rhs
lhs %...T>% rhs
Arguments
lhs |
A promise (e.g. the value returned by |
rhs |
A function call or expression applied to the resolved value. |
Value
A promises::promise(). %...>% resolves with the value of rhs
applied to the fulfilled value; %...!% handles a rejected promise; and
%...T>% (tee) applies rhs for its side effects and resolves with the
original fulfilled value. See promises::pipes.
Examples
if (interactive()) {
shiny::observeEvent(input$compute, {
lazy_data() |>
dplyr::filter(mpg >= input$min_mpg) |>
dplyr::collect() %...>% {
# `.` is the collected tibble
print(.)
}
})
}
Extract a single column from JSON data as a vector.
Description
Like collect(), pull() retrieves data asynchronously from
the browser, so it returns a promises::promise() that resolves to a
vector rather than returning the vector directly.
Usage
## S3 method for class 'tbl_lazy_json'
pull(.data, var = -1, name = NULL, ...)
Arguments
.data |
A |
var |
The column to extract. A bare name, a string, or a position.
Positive positions count from the left; negative positions count from the
right (e.g. |
name |
Ignored. Accepted for consistency with the generic; named
vectors are not produced for |
... |
Unused. Provided for consistency with the generic. |
Value
A promise resolving to a vector with the column's values.
Examples
if (interactive()) {
tbl(session, "mtcars") |>
pull(mpg) %...>% print()
}
Change column order of JSON data.
Description
Change column order of JSON data.
Usage
## S3 method for class 'tbl_lazy_json'
relocate(.data, ..., .before = NULL, .after = NULL)
Arguments
.data |
A |
... |
Columns to move. Bare names and character strings are accepted. |
.before, .after |
Destination of the columns selected by |
Details
Reordering happens in the browser by rebuilding each row's keys in
the new order. Columns not named in ... keep their relative order.
Value
A tbl_lazy_json object with the column reordering appended as a lazy
compute step, applied in the browser when the pipeline is evaluated.
Examples
if (interactive()) {
tbl(session, "mtcars") |> relocate(gear, carb)
tbl(session, "mtcars") |> relocate(mpg, .after = cyl)
}
Rename columns of JSON data.
Description
Rename columns of JSON data.
Usage
## S3 method for class 'tbl_lazy_json'
rename(.data, ...)
Arguments
.data |
A |
... |
Use |
Value
A tbl_lazy_json object with the rename appended as a lazy compute
step, applied in the browser when the pipeline is evaluated.
Examples
if (interactive()) {
tbl(session, "mtcars") |>
rename(miles_per_gallon = mpg, cylinders = cyl)
}
Select columns from JSON data.
Description
Select columns from JSON data.
Usage
## S3 method for class 'tbl_lazy_json'
select(.data, ...)
Arguments
.data |
A |
... |
Column names. |
Value
A tbl_lazy_json object with the column selection appended as a lazy
compute step, applied in the browser when the pipeline is evaluated.
Present computation steps.
Description
Present computation steps.
Usage
## S3 method for class 'tbl_lazy_json'
show_query(x, ...)
Arguments
x |
A |
... |
Filtering expressions. |
Value
The tbl_lazy_json object x, invisibly. Called for the side effect
of printing the accumulated compute steps to the console.
Select rows of JSON data by position.
Description
The slice() family picks rows by position or by ordering on a
column. When the data has been grouped with group_by(), slicing is
applied within each group.
Usage
## S3 method for class 'tbl_lazy_json'
slice(.data, ..., .by = NULL, .preserve = FALSE)
## S3 method for class 'tbl_lazy_json'
slice_head(.data, ..., n, prop, by = NULL)
## S3 method for class 'tbl_lazy_json'
slice_tail(.data, ..., n, prop, by = NULL)
## S3 method for class 'tbl_lazy_json'
slice_min(
.data,
order_by,
...,
n,
prop,
by = NULL,
with_ties = TRUE,
na_rm = FALSE
)
## S3 method for class 'tbl_lazy_json'
slice_max(
.data,
order_by,
...,
n,
prop,
by = NULL,
with_ties = TRUE,
na_rm = FALSE
)
Arguments
.data |
A |
... |
For |
.preserve |
Ignored. Accepted for consistency with the generic. |
n |
Number of rows to keep. Used by |
prop |
Proportion of rows to keep (0-1), an alternative to |
by, .by |
Ignored. Accepted for consistency with the generics; per-call
grouping is not applied (use |
order_by |
For |
with_ties, na_rm |
Ignored. Accepted for consistency with the
|
Details
All slicing is evaluated in the browser. slice_min()/slice_max()
order rows by the given column (ascending for min, descending for max) and
keep the first n (or prop).
Value
A tbl_lazy_json object with the row selection appended as a lazy
compute step. When the data is grouped with group_by(), the selection is
applied within each group in the browser at compute time.
Examples
if (interactive()) {
tbl(session, "mtcars") |> slice(1, 3, 5)
tbl(session, "mtcars") |> slice_head(n = 5)
tbl(session, "mtcars") |> group_by(cyl) |> slice_max(mpg, n = 2)
}
Summarise JSON data.
Description
Summarise JSON data.
Usage
## S3 method for class 'tbl_lazy_json'
summarise(.data, ...)
Arguments
.data |
A |
... |
Name-value pairs of summary functions.
The name gives the name of the column in the output.
The value should be a call to a summary function like
|
Value
A tbl_lazy_json object with the aggregation appended as a lazy
compute step. When evaluated it yields one row per group (or a single row
when ungrouped) with the summary columns.
Create a lazy JSON tbl
Description
Create a lazy JSON tbl
Usage
tbl_lazy_json(session, json_name, compute_steps = list())
Arguments
session |
A shiny |
json_name |
A character. |
compute_steps |
A list of compute steps to be
triggered when |
Value
An object of class tbl_lazy_json: a list holding the shiny
session, a state_id keying the data in the browser, and the list of
compute_steps to run when the pipeline is computed.
Remove grouping from JSON data.
Description
Drops grouping previously set with group_by(). With no
arguments all grouping is removed; supplying column names removes only those
columns from the grouping set (partial ungroup), matching dplyr::ungroup().
Usage
## S3 method for class 'tbl_lazy_json'
ungroup(x, ...)
Arguments
x |
A |
... |
Columns to remove from the grouping. Accepts the same inputs as
|
Details
Grouping is tracked as browser-side state consumed by group-aware
verbs such as summarise() and the slice() family. ungroup() appends a
step that clears or trims that state at compute time.
Value
A tbl_lazy_json object with the grouping state cleared (or trimmed
when columns are supplied), appended as a lazy compute step.
Examples
if (interactive()) {
tbl(session, "mtcars") |>
group_by(cyl) |>
ungroup()
}