| Title: | Manipulate 'JSON' Data in the Browser with a 'dplyr' Interface |
|---|---|
| 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. |
| Authors: | Maciej Banas [cre, aut], Krystian Igras [aut] |
| Maintainer: | Maciej Banas <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.1.0 |
| Built: | 2026-07-17 09:35:25 UTC |
| Source: | https://github.com/r-world-devs/jsplyr |
JSON data by column values.Arrange rows of JSON data by column values.
## S3 method for class 'tbl_lazy_json' arrange(.data, ..., .by_group = FALSE)## S3 method for class 'tbl_lazy_json' arrange(.data, ..., .by_group = FALSE)
.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 |
Sorting happens in the browser and is stable across ties, so the original row order is preserved within equal keys.
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().
if (interactive()) { tbl(session, "mtcars") |> arrange(cyl, desc(mpg)) }if (interactive()) { tbl(session, "mtcars") |> arrange(cyl, desc(mpg)) }
JSON data from the browser.Retrieve JSON data from the browser.
## S3 method for class 'tbl_lazy_json' collect(x, ..., raw = FALSE)## S3 method for class 'tbl_lazy_json' collect(x, ..., raw = FALSE)
x |
A |
... |
Unused. Provided for consistency with generic. |
raw |
A logical, if |
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.
JSON data in the browser.Compute JSON data in the browser.
## S3 method for class 'tbl_lazy_json' compute(x, ...)## S3 method for class 'tbl_lazy_json' compute(x, ...)
x |
A |
... |
Unused. Provided for consistency with generic. |
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
## S3 method for class 'ShinySession' copy_to(dest, df, ...)## S3 method for class 'ShinySession' copy_to(dest, df, ...)
dest |
A shiny |
df |
A local |
... |
Unused. Provided for consistency with generic. |
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.
JSON data.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.
## 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)## 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)
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. |
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.
if (interactive()) { tbl(session, "mtcars") |> count(cyl) tbl(session, "mtcars") |> count(cyl, sort = TRUE) tbl(session, "mtcars") |> group_by(cyl) |> tally() }if (interactive()) { tbl(session, "mtcars") |> count(cyl) tbl(session, "mtcars") |> count(cyl, sort = TRUE) tbl(session, "mtcars") |> group_by(cyl) |> tally() }
JSON data.Keep distinct records of JSON data.
## S3 method for class 'tbl_lazy_json' distinct(.data, ..., .keep_all = FALSE)## S3 method for class 'tbl_lazy_json' distinct(.data, ..., .keep_all = FALSE)
.data |
A |
... |
Column names to determine uniqueness. If empty, all columns are used. |
.keep_all |
If |
A tbl_lazy_json object with the de-duplication appended as a lazy
compute step, applied in the browser when the pipeline is evaluated.
JSON data.Add filter to JSON data.
## S3 method for class 'tbl_lazy_json' filter(.data, ...)## S3 method for class 'tbl_lazy_json' filter(.data, ...)
.data |
A |
... |
Filtering expressions. Comparisons ( |
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().
JSON data by one or more columns.Group JSON data by one or more columns.
## S3 method for class 'tbl_lazy_json' group_by(.data, ...)## S3 method for class 'tbl_lazy_json' group_by(.data, ...)
.data |
A |
... |
Columns to group by. Accepts bare column names as well as the
tidyselect helpers |
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.
Include the jsplyr JavaScript code in a Shiny app. To be put
in the UI part of the app.
include_jsplyr()include_jsplyr()
An htmlDependency object.
JSON tables.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.
## 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, ...)## 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, ...)
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. |
A tbl_lazy_json object with the join appended as a compute step.
JSON data.Add or modify columns in JSON data.
## S3 method for class 'tbl_lazy_json' mutate(.data, ...)## S3 method for class 'tbl_lazy_json' mutate(.data, ...)
.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:
|
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.
JSON data as a vector.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.
## S3 method for class 'tbl_lazy_json' pull(.data, var = -1, name = NULL, ...)## S3 method for class 'tbl_lazy_json' pull(.data, var = -1, name = NULL, ...)
.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. |
A promise resolving to a vector with the column's values.
if (interactive()) { tbl(session, "mtcars") |> pull(mpg) %...>% print() }if (interactive()) { tbl(session, "mtcars") |> pull(mpg) %...>% print() }
JSON data.Change column order of JSON data.
## S3 method for class 'tbl_lazy_json' relocate(.data, ..., .before = NULL, .after = NULL)## S3 method for class 'tbl_lazy_json' relocate(.data, ..., .before = NULL, .after = NULL)
.data |
A |
... |
Columns to move. Bare names and character strings are accepted. |
.before, .after
|
Destination of the columns selected by |
Reordering happens in the browser by rebuilding each row's keys in
the new order. Columns not named in ... keep their relative order.
A tbl_lazy_json object with the column reordering appended as a lazy
compute step, applied in the browser when the pipeline is evaluated.
if (interactive()) { tbl(session, "mtcars") |> relocate(gear, carb) tbl(session, "mtcars") |> relocate(mpg, .after = cyl) }if (interactive()) { tbl(session, "mtcars") |> relocate(gear, carb) tbl(session, "mtcars") |> relocate(mpg, .after = cyl) }
JSON data.Rename columns of JSON data.
## S3 method for class 'tbl_lazy_json' rename(.data, ...)## S3 method for class 'tbl_lazy_json' rename(.data, ...)
.data |
A |
... |
Use |
A tbl_lazy_json object with the rename appended as a lazy compute
step, applied in the browser when the pipeline is evaluated.
if (interactive()) { tbl(session, "mtcars") |> rename(miles_per_gallon = mpg, cylinders = cyl) }if (interactive()) { tbl(session, "mtcars") |> rename(miles_per_gallon = mpg, cylinders = cyl) }
JSON data.Select columns from JSON data.
## S3 method for class 'tbl_lazy_json' select(.data, ...)## S3 method for class 'tbl_lazy_json' select(.data, ...)
.data |
A |
... |
Column names. |
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.
## S3 method for class 'tbl_lazy_json' show_query(x, ...)## S3 method for class 'tbl_lazy_json' show_query(x, ...)
x |
A |
... |
Filtering expressions. |
The tbl_lazy_json object x, invisibly. Called for the side effect
of printing the accumulated compute steps to the console.
JSON data by position.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.
## 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 )## 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 )
.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
|
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).
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.
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) }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) }
JSON data.Summarise JSON data.
## S3 method for class 'tbl_lazy_json' summarise(.data, ...)## S3 method for class 'tbl_lazy_json' summarise(.data, ...)
.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
|
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
tbl_lazy_json(session, json_name, compute_steps = list())tbl_lazy_json(session, json_name, compute_steps = list())
session |
A shiny |
json_name |
A character. |
compute_steps |
A list of compute steps to be
triggered when |
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.
JSON data.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().
## S3 method for class 'tbl_lazy_json' ungroup(x, ...)## S3 method for class 'tbl_lazy_json' ungroup(x, ...)
x |
A |
... |
Columns to remove from the grouping. Accepts the same inputs as
|
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.
A tbl_lazy_json object with the grouping state cleared (or trimmed
when columns are supplied), appended as a lazy compute step.
if (interactive()) { tbl(session, "mtcars") |> group_by(cyl) |> ungroup() }if (interactive()) { tbl(session, "mtcars") |> group_by(cyl) |> ungroup() }