Title: | Create Interactive Trelliscope Displays |
---|---|
Description: | Trelliscope is a scalable, flexible, interactive approach to visualizing data (Hafen, 2013 <doi:10.1109/LDAV.2013.6675164>). This package provides methods that make it easy to create a Trelliscope display specification for TrelliscopeJS. High-level functions are provided for creating displays from within 'tidyverse' or 'ggplot2' workflows. Low-level functions are also provided for creating new interfaces. |
Authors: | Ryan Hafen [aut, cre] , Barret Schloerke [aut] |
Maintainer: | Ryan Hafen <[email protected]> |
License: | BSD_3_clause + file LICENSE |
Version: | 0.2.10 |
Built: | 2024-10-31 03:05:09 UTC |
Source: | https://github.com/hafen/trelliscopejs |
Create interactive Trelliscope displays
https://hafen.github.io/trelliscopejs/
help(package = trelliscopejs)
help(package = trelliscopejs)
Cast a data frame as a cognostics data frame
as_cognostics( x, cond_cols, key_col = NULL, cog_desc = NULL, needs_key = TRUE, needs_cond = TRUE, group = "common" )
as_cognostics( x, cond_cols, key_col = NULL, cog_desc = NULL, needs_key = TRUE, needs_cond = TRUE, group = "common" )
x |
a data frame |
cond_cols |
the column name(s) that comprise the conditioning variables |
key_col |
the column name that indicates the panel key |
cog_desc |
an optional named list of descriptions for the cognostics columns |
needs_key |
does the result need to have a "key" column? |
needs_cond |
does the result need to have conditioning variable columns? |
group |
value to be used in the |
Cast a column of a cognostics data frame as a cognostic object
cog( val = NULL, desc = "", group = "common", type = NULL, default_label = FALSE, default_active = TRUE, filterable = TRUE, sortable = TRUE, log = NULL )
cog( val = NULL, desc = "", group = "common", type = NULL, default_label = FALSE, default_active = TRUE, filterable = TRUE, sortable = TRUE, log = NULL )
val |
a scalar value (numeric, character, date, etc.) |
desc |
a description for this cognostic value |
group |
optional categorization of the cognostic for organizational purposes in the viewer (currently not implemented in the viewer) |
type |
the desired type of cognostic you would like to compute (see details) |
default_label |
should this cognostic be used as a panel label in the viewer by default? |
default_active |
should this cognostic be active (available for sort / filter / sample) by default? |
filterable |
should this cognostic be filterable? Default is |
sortable |
should this cognostic be sortable? |
log |
when being used in the viewer for visual univariate and bivariate filters, should the log be computed? Useful when the distribution of the cognostic is very long-tailed or has large outliers. Can either be a logical or a positive integer indicating the base. |
Different types of cognostics can be specified through the type
argument that will affect how the user is able to interact with those cognostics in the viewer. This can usually be ignored because it will be inferred from the implicit data type of val
. But there are special types of cognostics, such as geographic coordinates and relations (not implemented) that can be specified as well. Current possibilities for type
are "key", "integer", "numeric", "factor", "date", "time", "href".
object of class "cog"
library(dplyr) library(tidyr) library(purrr) library(ggplot2) library(plotly) mpg_cog <- mpg %>% nest(data = !one_of(c("manufacturer", "class"))) %>% mutate( cogs = map_cog(data, ~ tibble( mean_city_mpg = cog(mean(.$cty), desc = "Mean city mpg"), mean_hwy_mpg = cog(mean(.$hwy), desc = "Mean highway mpg"), most_common_drv = cog(tail(names(table(.$drv)), 1), desc = "Most common drive type") )), panel = map_plot(data, function(x) { plot_ly(data = x, x = ~cty, y = ~hwy, type = "scatter", mode = "markers") %>% layout( xaxis = list(range = c(9, 47)), yaxis = list(range = c(7, 37))) }) ) trelliscope(mpg_cog, name = "city_vs_highway_mpg", nrow = 1, ncol = 2)
library(dplyr) library(tidyr) library(purrr) library(ggplot2) library(plotly) mpg_cog <- mpg %>% nest(data = !one_of(c("manufacturer", "class"))) %>% mutate( cogs = map_cog(data, ~ tibble( mean_city_mpg = cog(mean(.$cty), desc = "Mean city mpg"), mean_hwy_mpg = cog(mean(.$hwy), desc = "Mean highway mpg"), most_common_drv = cog(tail(names(table(.$drv)), 1), desc = "Most common drive type") )), panel = map_plot(data, function(x) { plot_ly(data = x, x = ~cty, y = ~hwy, type = "scatter", mode = "markers") %>% layout( xaxis = list(range = c(9, 47)), yaxis = list(range = c(7, 37))) }) ) trelliscope(mpg_cog, name = "city_vs_highway_mpg", nrow = 1, ncol = 2)
Helper function for creating a cognostic for a link to another display in a filtered state
cog_disp_filter( display, var, val, desc = "link", group = "common", type = c("href", "href_hash"), default_label = FALSE, default_active = FALSE, filterable = FALSE, sortable = FALSE )
cog_disp_filter( display, var, val, desc = "link", group = "common", type = c("href", "href_hash"), default_label = FALSE, default_active = FALSE, filterable = FALSE, sortable = FALSE )
display |
A string indicating the name of the display to link to. |
var |
A string indicating the variable name to filter on. |
val |
A string indicating the value of the filter. |
desc |
a description for this cognostic value |
group |
optional categorization of the cognostic for organizational purposes in the viewer (currently not implemented in the viewer) |
type |
of either "href" or "href_hash". "href" will open the link in a new page. "href_hash" will update the page's hash and reload the page (useful when changing state inside an iframe) |
default_label |
should this cognostic be used as a panel label in the viewer by default? |
default_active |
should this cognostic be active (available for sort / filter / sample) by default? |
filterable |
should this cognostic be filterable? Default is |
sortable |
should this cognostic be sortable? |
Create href to be used as cognostics in a trelliscope display
cog_href( x, desc = "link", group = "common", type = c("href", "href_hash"), default_label = FALSE, default_active = FALSE, filterable = FALSE, sortable = FALSE, log = FALSE )
cog_href( x, desc = "link", group = "common", type = c("href", "href_hash"), default_label = FALSE, default_active = FALSE, filterable = FALSE, sortable = FALSE, log = FALSE )
x |
URL to link to |
desc , group , default_label , default_active , filterable , sortable , log
|
arguments passed to |
type |
of either "href" or "href_hash". "href" will open the link in a new page. "href_hash" will update the page's hash and reload the page (useful when changing state inside an iframe) |
library(dplyr) library(tidyr) library(plotly) iris %>% nest(data = -Species) %>% mutate( panel = map_plot(data, function(x) { plot_ly(data = x, x = ~Sepal.Length, y = ~Sepal.Width, type = "scatter", mode = "markers") }), wiki_link = cog_href(paste0("https://en.wikipedia.org/wiki/Iris_", tolower(Species))[1], default_label = TRUE, desc = "link to species on wikipedia") ) %>% trelliscope(name = "iris_species", ncol = 3)
library(dplyr) library(tidyr) library(plotly) iris %>% nest(data = -Species) %>% mutate( panel = map_plot(data, function(x) { plot_ly(data = x, x = ~Sepal.Length, y = ~Sepal.Width, type = "scatter", mode = "markers") }), wiki_link = cog_href(paste0("https://en.wikipedia.org/wiki/Iris_", tolower(Species))[1], default_label = TRUE, desc = "link to species on wikipedia") ) %>% trelliscope(name = "iris_species", ncol = 3)
Cogs Wrapper Function
cogs(.x, .f, ...)
cogs(.x, .f, ...)
.x |
a list or atomic vector (see |
.f |
a function, formula, or atomic vector (see |
... |
additional arguments passed on to .f (see |
See map
library(dplyr) library(tidyr) library(plotly) ggplot2::mpg %>% nest(data = !one_of(c("manufacturer", "class"))) %>% mutate( additional_cogs = map_cog(data, function(x) { tibble( max_city_mpg = cog(max(x$cty), desc = "Max city mpg"), min_city_mpg = cog(min(x$cty), desc = "Min city mpg")) }), panel = map_plot(data, function(x) { plot_ly(data = x, x = ~cty, y = ~hwy, type = "scatter", mode = "markers") }) ) %>% trelliscope(name = "city_vs_highway_mpg", nrow = 1, ncol = 2)
library(dplyr) library(tidyr) library(plotly) ggplot2::mpg %>% nest(data = !one_of(c("manufacturer", "class"))) %>% mutate( additional_cogs = map_cog(data, function(x) { tibble( max_city_mpg = cog(max(x$cty), desc = "Max city mpg"), min_city_mpg = cog(min(x$cty), desc = "Min city mpg")) }), panel = map_plot(data, function(x) { plot_ly(data = x, x = ~cty, y = ~hwy, type = "scatter", mode = "markers") }) ) %>% trelliscope(name = "city_vs_highway_mpg", nrow = 1, ncol = 2)
Create a cognostics template that can be edited and used to specify cognostics in a display #' @param x a data frame that will be used as an input for the trelliscope display. If NULL, a blank template will be created.
create_cog_template(x = NULL)
create_cog_template(x = NULL)
The input 'x' can be a starting point and does not need to contain all variables that may be added later. Also note that after you edit the output (for example using the editData package, or writing to a csv and editing in Excel) to reflect how you would like the cognostics to display in the viewer, you can Add this specification to your trelliscope display with [add_cog_template()].
Facet Trelliscope
facet_trelliscope( facets, nrow = 1, ncol = 1, scales = "same", name = NULL, group = "common", desc = ggplot2::waiver(), md_desc = ggplot2::waiver(), path = NULL, height = 500, width = 500, inputs = NULL, state = NULL, views = NULL, jsonp = TRUE, as_plotly = FALSE, plotly_args = NULL, plotly_cfg = NULL, split_sig = NULL, google_analytics_id = NULL, self_contained = FALSE, thumb = TRUE, require_token = FALSE, id = NULL, order = 1, disclaimer = FALSE, update_plots = TRUE, auto_cog = FALSE, split_layout = FALSE, data = ggplot2::waiver() )
facet_trelliscope( facets, nrow = 1, ncol = 1, scales = "same", name = NULL, group = "common", desc = ggplot2::waiver(), md_desc = ggplot2::waiver(), path = NULL, height = 500, width = 500, inputs = NULL, state = NULL, views = NULL, jsonp = TRUE, as_plotly = FALSE, plotly_args = NULL, plotly_cfg = NULL, split_sig = NULL, google_analytics_id = NULL, self_contained = FALSE, thumb = TRUE, require_token = FALSE, id = NULL, order = 1, disclaimer = FALSE, update_plots = TRUE, auto_cog = FALSE, split_layout = FALSE, data = ggplot2::waiver() )
facets |
formula to facet the panels on. Similar to |
nrow |
the number of rows of panels to display by default |
ncol |
the number of columns of panels to display by default |
scales |
should scales be the same ( |
name |
name of the display |
group |
group that the display belongs to |
desc |
description of the display |
md_desc |
optional string of markdown that will be shown in the viewer for additional context about the display |
path |
the base directory of the trelliscope application |
height |
height in pixels of each panel |
width |
width in pixels of each panel |
inputs |
optional set of input specifications (using |
state |
the initial state the display will open in |
views |
an optional list of pre-specified views of the display (experimental) |
jsonp |
should json for display object be jsonp (TRUE) or json (FALSE)? |
as_plotly |
should the panels be written as plotly objects? |
plotly_args |
optional named list of arguments to send to |
plotly_cfg |
optional named list of arguments to send to plotly's |
split_sig |
optional string that specifies the "signature" of the data splitting. If not specified, this is calculated as the md5 hash of the sorted unique facet variables. This is used to identify "related displays" - different displays that are based on the same faceting scheme. This parameter should only be specified manually if a display's faceting is mostly similar to another display's. |
google_analytics_id |
optional string specifying Google Analytics ID |
self_contained |
should the Trelliscope display be a self-contained html document? (see note) |
thumb |
should a thumbnail be created? |
require_token |
require a special token for all displays to be visible (experimental) |
id |
set a hard-coded ID for this app (do not set this if the display will be part of a larger web page) |
order |
an integer indicating the order that the display should appear in if using multiple displays |
disclaimer |
an optional string of html to include as a disclaimer for the set of displays |
auto_cog |
should auto cogs be computed (if possible)? |
split_layout |
boolean that determines if the layout is split into components like a facet_grid vs. individual panels like facet_wrap. Only applies to ggplot2 plot objects. |
data |
data used for faceting. Defaults to the first layer data |
Note that self_contained
is severely limiting and should only be used in cases where you would either like your display to show up in the RStudio viewer pane, in an interactive R Markdown Notebook, or in a self-contained R Markdown html document.
Note that self_contained
is severely limiting and should only be used in cases where you would either like your display to show up in the RStudio viewer pane, in an interactive R Markdown Notebook, or in a self-contained R Markdown html document.
## Not run: library(ggplot2) # basically swap out facet_wrap for facet_trelliscope qplot(cty, hwy, data = mpg) + facet_trelliscope(~ class + manufacturer) # not required, but if you set labels, these will be added as # descriptions to the cognostics that are automatically computed mpg <- set_labels(mpg, mpg_labels) qplot(cty, hwy, data = mpg) + theme_bw() + facet_trelliscope(~ manufacturer + class, nrow = 2, ncol = 4) # using plotly library(plotly) qplot(cty, hwy, data = mpg) + theme_bw() + facet_trelliscope(~ manufacturer + class, nrow = 2, ncol = 4, as_plotly = TRUE) qplot(class, cty, data = mpg, geom = c("boxplot", "jitter"), na.rm = TRUE) + facet_trelliscope(~ class, ncol = 7, height = 800, width = 200, state = list(sort = list(sort_spec("cty_mean")))) + theme_bw() library(gapminder) qplot(year, lifeExp, data = gapminder) + xlim(1948, 2011) + ylim(10, 95) + theme_bw() + facet_trelliscope(~ country + continent, nrow = 2, ncol = 7, width = 300, as_plotly = TRUE, plotly_cfg = list(displayModeBar = FALSE)) ## End(Not run)
## Not run: library(ggplot2) # basically swap out facet_wrap for facet_trelliscope qplot(cty, hwy, data = mpg) + facet_trelliscope(~ class + manufacturer) # not required, but if you set labels, these will be added as # descriptions to the cognostics that are automatically computed mpg <- set_labels(mpg, mpg_labels) qplot(cty, hwy, data = mpg) + theme_bw() + facet_trelliscope(~ manufacturer + class, nrow = 2, ncol = 4) # using plotly library(plotly) qplot(cty, hwy, data = mpg) + theme_bw() + facet_trelliscope(~ manufacturer + class, nrow = 2, ncol = 4, as_plotly = TRUE) qplot(class, cty, data = mpg, geom = c("boxplot", "jitter"), na.rm = TRUE) + facet_trelliscope(~ class, ncol = 7, height = 800, width = 200, state = list(sort = list(sort_spec("cty_mean")))) + theme_bw() library(gapminder) qplot(year, lifeExp, data = gapminder) + xlim(1948, 2011) + ylim(10, 95) + theme_bw() + facet_trelliscope(~ country + continent, nrow = 2, ncol = 7, width = 300, as_plotly = TRUE, plotly_cfg = list(displayModeBar = FALSE)) ## End(Not run)
Cast a vector of URLs pointing to images as an image panel source
img_panel(x)
img_panel(x)
x |
a vector of URLs pointing to images |
Cast a vector of URLs pointing to local images as an image panel source
img_panel_local(x)
img_panel_local(x)
x |
a vector of URLs pointing to images |
x
must be paths relative to the path
argument passed to trelliscope
.
## Not run: # assuming images are available locally in relative path pokemon_local/images pokemon$img <- img_panel_local(paste0("images/", basename(pokemon$url_image))) trelliscope(pokemon, name = "pokemon", path = "pokemon_local") ## End(Not run)
## Not run: # assuming images are available locally in relative path pokemon_local/images pokemon$img <- img_panel_local(paste0("images/", basename(pokemon$url_image))) trelliscope(pokemon, name = "pokemon", path = "pokemon_local") ## End(Not run)
Specify a collection of input cognostics to be stored in browser localStorage
input_cogs(..., feedback_email = NULL, extra_cogs = NULL)
input_cogs(..., feedback_email = NULL, extra_cogs = NULL)
feedback_email |
optional feedback email address that input feedback can be sent to |
extra_cogs |
optional vector of names of non-input "regular" cognostics to include in the csv output |
... |
objects created by any of |
Specify a collection of input cognostics to be stored using an API
input_cogs_api( ..., set_url, get_url, get_request_options = list(mode = "cors", method = "GET", headers = list(`Content-Type` = "application/json", Accept = "application/json")), set_request_options = list(mode = "cors", method = "POST", headers = list(`Content-Type` = "application/json", Accept = "application/json")) )
input_cogs_api( ..., set_url, get_url, get_request_options = list(mode = "cors", method = "GET", headers = list(`Content-Type` = "application/json", Accept = "application/json")), set_request_options = list(mode = "cors", method = "POST", headers = list(`Content-Type` = "application/json", Accept = "application/json")) )
set_url |
URL of the API endpoint for setting a single input |
get_url |
URL of the API endpoint for getting all inputs for the display |
get_request_options |
request options for the API call to set inputs |
set_request_options |
request options for the API call to get inputs |
... |
objects created by any of |
See [here](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch#supplying_request_options for more information about request options.
Specify a radio button input
input_radio(name, desc = NULL, options, group = NULL, default_label = TRUE)
input_radio(name, desc = NULL, options, group = NULL, default_label = TRUE)
name |
name of the input |
desc |
optional description of the input |
options |
a character vector of options to select between |
group |
optional categorization of the input for organizational purposes in the viewer (currently not implemented in the viewer) |
default_label |
should this input be shown under the panel in the viewer by default? |
Specify a text input
input_text( name, desc = NULL, width = 80, height = 3, group = NULL, default_label = TRUE )
input_text( name, desc = NULL, width = 80, height = 3, group = NULL, default_label = TRUE )
name |
name of the input |
desc |
optional description of the input |
width |
width (in characters) of the text box popout |
height |
height (in lines of text) of the text box popout |
group |
optional categorization of the input for organizational purposes in the viewer (currently not implemented in the viewer) |
default_label |
should this input be shown under the panel in the viewer by default? |
Apply a function to each element of a vector and return a vector of cognostics data frames
map_cog(.x, .f, ...)
map_cog(.x, .f, ...)
.x |
a list or atomic vector (see |
.f |
a function, formula, or atomic vector (see |
... |
additional arguments passed on to .f (see |
See map
library(dplyr) library(tidyr) library(plotly) ggplot2::mpg %>% nest(data = !one_of(c("manufacturer", "class"))) %>% mutate( cog = map_cog(data, function(x) tibble(mean_hwy = mean(x$hwy))), panel = map_plot(data, function(x) { plot_ly(data = x, x = ~cty, y = ~hwy, type = "scatter", mode = "markers") }) ) %>% trelliscope(name = "city_vs_highway_mpg")
library(dplyr) library(tidyr) library(plotly) ggplot2::mpg %>% nest(data = !one_of(c("manufacturer", "class"))) %>% mutate( cog = map_cog(data, function(x) tibble(mean_hwy = mean(x$hwy))), panel = map_plot(data, function(x) { plot_ly(data = x, x = ~cty, y = ~hwy, type = "scatter", mode = "markers") }) ) %>% trelliscope(name = "city_vs_highway_mpg")
Apply a function to each element of a vector and return a vector of plots
map_plot(.x, .f, ...)
map_plot(.x, .f, ...)
.x |
a list or atomic vector (see |
.f |
a function, formula, or atomic vector (see |
... |
additional arguments passed on to .f (see |
See map
library(dplyr) library(tidyr) library(purrr) library(plotly) library(gapminder) # nest gapminder data by country by_country <- gapminder %>% nest(data = !one_of(c("country", "continent"))) # add in a plot column with map_plot by_country <- by_country %>% mutate( panel = map_plot(data, function(x) { plot_ly(data = x, x = ~year, y = ~lifeExp, type = "scatter", mode = "markers") %>% layout( xaxis = list(range = c(1948, 2011)), yaxis = list(range = c(10, 95))) })) # plot it by_country %>% trelliscope("gapminder", nrow = 2, ncol = 7, width = 300) # example using mpg data ggplot2::mpg %>% nest(data = !one_of(c("manufacturer", "class"))) %>% mutate(panel = map_plot(data, function(x) { plot_ly(data = x, x = ~hwy, y = ~cty, type = "scatter", mode = "markers") })) %>% trelliscope(name = "city_vs_highway_mpg")
library(dplyr) library(tidyr) library(purrr) library(plotly) library(gapminder) # nest gapminder data by country by_country <- gapminder %>% nest(data = !one_of(c("country", "continent"))) # add in a plot column with map_plot by_country <- by_country %>% mutate( panel = map_plot(data, function(x) { plot_ly(data = x, x = ~year, y = ~lifeExp, type = "scatter", mode = "markers") %>% layout( xaxis = list(range = c(1948, 2011)), yaxis = list(range = c(10, 95))) })) # plot it by_country %>% trelliscope("gapminder", nrow = 2, ncol = 7, width = 300) # example using mpg data ggplot2::mpg %>% nest(data = !one_of(c("manufacturer", "class"))) %>% mutate(panel = map_plot(data, function(x) { plot_ly(data = x, x = ~hwy, y = ~cty, type = "scatter", mode = "markers") })) %>% trelliscope(name = "city_vs_highway_mpg")
Map over multiple inputs simultaneously and return a vector of cognostics data frames
map2_cog(.x, .y, .f, ...) pmap_cog(.l, .f, ...)
map2_cog(.x, .y, .f, ...) pmap_cog(.l, .f, ...)
.x , .y
|
Vectors of the same length. A vector of length 1 will be recycled. |
.f |
A function, formula, or atomic vector (see |
... |
additional arguments passed on to .f. |
.l |
A list of lists. The length of .l determines the number of arguments that .f will be called with. List names will be used if present. |
See map2
library(tidyr) library(purrr) library(plotly) library(dplyr) iris %>% nest(data = -Species) %>% mutate( mod = map(data, ~ lm(Sepal.Length ~ Sepal.Width, data = .x)), cogs = map2_cog(data, mod, function(data, mod) { tibble(max_sl = max(data$Sepal.Length), slope = coef(mod)[2]) }), panel = map2_plot(data, mod, function(data, mod) { plot_ly(data = data, x = ~Sepal.Width, y = ~Sepal.Length, type = "scatter", mode = "markers", name = "data") %>% add_trace(data = data, x = ~Sepal.Width, y = ~predict(mod), mode = "lines", name = "lm") })) %>% trelliscope(name = "iris")
library(tidyr) library(purrr) library(plotly) library(dplyr) iris %>% nest(data = -Species) %>% mutate( mod = map(data, ~ lm(Sepal.Length ~ Sepal.Width, data = .x)), cogs = map2_cog(data, mod, function(data, mod) { tibble(max_sl = max(data$Sepal.Length), slope = coef(mod)[2]) }), panel = map2_plot(data, mod, function(data, mod) { plot_ly(data = data, x = ~Sepal.Width, y = ~Sepal.Length, type = "scatter", mode = "markers", name = "data") %>% add_trace(data = data, x = ~Sepal.Width, y = ~predict(mod), mode = "lines", name = "lm") })) %>% trelliscope(name = "iris")
Map over multiple inputs simultaneously and return a vector of plots
map2_plot(.x, .y, .f, ...) pmap_plot(.l, .f, ...)
map2_plot(.x, .y, .f, ...) pmap_plot(.l, .f, ...)
.x , .y
|
Vectors of the same length. A vector of length 1 will be recycled. |
.f |
A function, formula, or atomic vector (see |
... |
additional arguments passed on to .f. |
.l |
A list of lists. The length of .l determines the number of arguments that .f will be called with. List names will be used if present. |
See map2
library(tidyr) library(purrr) library(plotly) library(dplyr) iris %>% nest(data = -Species) %>% mutate( mod = map(data, ~ lm(Sepal.Length ~ Sepal.Width, data = .x)), panel = map2_plot(data, mod, function(data, mod) { plot_ly(data = data, x = ~Sepal.Width, y = ~Sepal.Length, type = "scatter", mode = "markers", name = "data") %>% add_trace(data = data, x = ~Sepal.Width, y = ~predict(mod), mode = "lines", name = "lm") })) %>% trelliscope(name = "iris")
library(tidyr) library(purrr) library(plotly) library(dplyr) iris %>% nest(data = -Species) %>% mutate( mod = map(data, ~ lm(Sepal.Length ~ Sepal.Width, data = .x)), panel = map2_plot(data, mod, function(data, mod) { plot_ly(data = data, x = ~Sepal.Width, y = ~Sepal.Length, type = "scatter", mode = "markers", name = "data") %>% add_trace(data = data, x = ~Sepal.Width, y = ~predict(mod), mode = "lines", name = "lm") })) %>% trelliscope(name = "iris")
Specify a markdown description for a display
md_description( content = "", title = "Information About This Display", show = FALSE )
md_description( content = "", title = "Information About This Display", show = FALSE )
content |
Markdown content |
title |
Title of the dialog box that displays this content |
show |
should the markdown description be shown by default when the display is loaded? |
Labels for ggplot2 "mpg" data
mpg_labels
mpg_labels
An object of class list
of length 10.
Panels Wrapper Function
panels(.x, .f, ...)
panels(.x, .f, ...)
.x |
a list or atomic vector (see |
.f |
a function, formula, or atomic vector (see |
... |
additional arguments passed on to .f (see |
See map
library(dplyr) library(tidyr) library(plotly) ggplot2::mpg %>% nest(data = !one_of(c("manufacturer", "class"))) %>% mutate(panel = map_plot(data, function(x) { plot_ly(data = x, x = ~hwy, y = ~cty, type = "scatter", mode = "markers") })) %>% trelliscope(name = "city_vs_highway_mpg")
library(dplyr) library(tidyr) library(plotly) ggplot2::mpg %>% nest(data = !one_of(c("manufacturer", "class"))) %>% mutate(panel = map_plot(data, function(x) { plot_ly(data = x, x = ~hwy, y = ~cty, type = "scatter", mode = "markers") })) %>% trelliscope(name = "city_vs_highway_mpg")
Set up all auxiliary files needed for a Trelliscope app
prepare_display( base_path, id, self_contained = FALSE, jsonp = TRUE, require_token = FALSE, disclaimer = FALSE, pb = NULL )
prepare_display( base_path, id, self_contained = FALSE, jsonp = TRUE, require_token = FALSE, disclaimer = FALSE, pb = NULL )
base_path |
the base directory of the trelliscope application |
id |
a unique id for the application |
self_contained |
should the Trelliscope display be a self-contained html document? |
jsonp |
should json for display list and app config be jsonp (TRUE) or json (FALSE)? |
require_token |
require a special token for all displays to be visible (experimental) |
disclaimer |
an optional string of html to include as a disclaimer for the set of displays |
pb |
optional progress bar object to pass in and use to report progress |
Print facet trelliscope object
## S3 method for class 'facet_trelliscope' print(x, ...)
## S3 method for class 'facet_trelliscope' print(x, ...)
x |
plot object |
... |
ignored |
Set labels for a data frame
set_labels(dat, label_list)
set_labels(dat, label_list)
dat |
a data frame to apply labels to |
label_list |
a named list with names matching those of |
data frame with labels attached as attributes (attached to each column and named "label")
Specify how a display should be sorted
sort_spec(name, dir = "asc")
sort_spec(name, dir = "asc")
name |
variable name to sort on |
dir |
direction to sort ('asc' or 'desc') |
Use fidelius to password protect a trelliscope display
tr_charm(x, ...)
tr_charm(x, ...)
x |
an object of class "facet_trelliscope" or "trelliscopejs_widget" |
... |
arguments passed to [fidelius::charm()] |
Create a Trelliscope Display
trelliscope( x, name, group = "common", panel_col = NULL, cond_cols = NULL, desc = "", md_desc = "", path, height = 500, width = 500, inputs = NULL, google_analytics_id = NULL, auto_cog = FALSE, state = NULL, views = NULL, nrow = 1, ncol = 1, jsonp = TRUE, split_sig = NULL, self_contained = FALSE, thumb = FALSE, require_token = FALSE, id = NULL, order = 1, disclaimer = FALSE, update_plots = TRUE )
trelliscope( x, name, group = "common", panel_col = NULL, cond_cols = NULL, desc = "", md_desc = "", path, height = 500, width = 500, inputs = NULL, google_analytics_id = NULL, auto_cog = FALSE, state = NULL, views = NULL, nrow = 1, ncol = 1, jsonp = TRUE, split_sig = NULL, self_contained = FALSE, thumb = FALSE, require_token = FALSE, id = NULL, order = 1, disclaimer = FALSE, update_plots = TRUE )
x |
an object to create at trelliscope display for |
name |
name of the display |
group |
group that the display belongs to |
panel_col |
optional string specifying the column to use for panels (if there are multiple plot columns in |
cond_cols |
optionsl vector of columns to specify as "conditioning" columns - combined they must be unique and not have any missing values |
desc |
optional text description of the display |
md_desc |
optional string of markdown that will be shown in the viewer for additional context about the display |
path |
the base directory of the trelliscope application |
height |
height in pixels of each panel |
width |
width in pixels of each panel |
inputs |
optional set of input specifications (using |
google_analytics_id |
optional string specifying Google Analytics ID |
auto_cog |
should auto cogs be computed (if possible)? |
state |
the initial state the display will open in |
views |
an optional list of pre-specified views of the display (experimental) |
nrow |
the number of rows of panels to display by default |
ncol |
the number of columns of panels to display by default |
jsonp |
should json for display object be jsonp (TRUE) or json (FALSE)? |
split_sig |
optional string that specifies the "signature" of the data splitting. If not specified, this is calculated as the md5 hash of the sorted unique facet variables. This is used to identify "related displays" - different displays that are based on the same faceting scheme. This parameter should only be specified manually if a display's faceting is mostly similar to another display's. |
self_contained |
should the Trelliscope display be a self-contained html document? (see note) |
thumb |
should a thumbnail be created? |
require_token |
require a special token for all displays to be visible (experimental) |
id |
set a hard-coded ID for this app (do not set this if the display will be part of a larger web page) |
order |
an integer indicating the order that the display should appear in if using multiple displays |
disclaimer |
an optional string of html to include as a disclaimer for the set of displays |
update_plots |
should the plots be updated? This is to allow slight updates to the underlying display data without the need to re-render all of the plots. Use it carefully. |
Note that self_contained
is severely limiting and should only be used in cases where you would either like your display to show up in the RStudio viewer pane, in an interactive R Markdown Notebook, or in a self-contained R Markdown html document.
## Not run: library(dplyr) library(tidyr) library(purrr) library(plotly) library(ggplot2) # tidyverse + plotly d <- mpg %>% nest(data = !one_of(c("manufacturer", "class"))) %>% mutate( mean_city_mpg = map_dbl(data, ~ mean(.$cty)), panel = map_plot(data, function(x) { plot_ly(data = x, x = ~cty, y = ~hwy, type = "scatter", mode = "markers") }) ) d %>% trelliscope(name = "city_vs_highway_mpg") # set default layout d %>% trelliscope(name = "city_vs_highway_mpg", nrow = 2, ncol = 3) # set the output path for where files will be stored my_displays <- tempfile() d %>% trelliscope(name = "city_vs_highway_mpg", path = my_displays) # multiple displays can be added to the same path and all will be available in the viewer d %>% trelliscope(name = "city_vs_highway_mpg2", path = my_displays) # ordering the data frame will set default sort order of the display d %>% arrange(-mean_city_mpg) %>% trelliscope(name = "city_vs_highway_mpg") # tidyverse + ggplot2 mpg %>% nest(data = !one_of(c("manufacturer", "class"))) %>% mutate( panel = map_plot(data, ~ qplot(cty, hwy, data = .) + xlab("cty") + ylab("hwy") + xlim(7, 37) + ylim(9, 47) + theme_bw())) %>% trelliscope(name = "tidy_gg") # computing additional cognostics mpg_cog <- mpg %>% nest(data = !one_of(c("manufacturer", "class"))) %>% mutate( cogs = map_cog(data, ~ tibble( mean_city_mpg = mean(.$cty), mean_hwy_mpg = mean(.$hwy), most_common_drv = tail(names(table(.$drv)), 1) )) ) # computing additional cognostics explicitly using cog() # so we can specify descriptions, etc. mpg_cog2 <- mpg %>% nest(data = !one_of(c("manufacturer", "class"))) %>% mutate( cogs = map_cog(data, ~ tibble( mean_city_mpg = cog(mean(.$cty), desc = "Mean city mpg"), mean_hwy_mpg = cog(mean(.$hwy), desc = "Mean highway mpg"), most_common_drv = cog(tail(names(table(.$drv)), 1), desc = "Most common drive type") )), panel = map_plot(data, function(x) { plot_ly(data = x, x = ~cty, y = ~hwy, type = "scatter", mode = "markers") %>% layout( xaxis = list(range = c(9, 47)), yaxis = list(range = c(7, 37))) }) ) mpg_cog2 %>% trelliscope(name = "city_vs_highway_mpg", nrow = 1, ncol = 2) ## End(Not run)
## Not run: library(dplyr) library(tidyr) library(purrr) library(plotly) library(ggplot2) # tidyverse + plotly d <- mpg %>% nest(data = !one_of(c("manufacturer", "class"))) %>% mutate( mean_city_mpg = map_dbl(data, ~ mean(.$cty)), panel = map_plot(data, function(x) { plot_ly(data = x, x = ~cty, y = ~hwy, type = "scatter", mode = "markers") }) ) d %>% trelliscope(name = "city_vs_highway_mpg") # set default layout d %>% trelliscope(name = "city_vs_highway_mpg", nrow = 2, ncol = 3) # set the output path for where files will be stored my_displays <- tempfile() d %>% trelliscope(name = "city_vs_highway_mpg", path = my_displays) # multiple displays can be added to the same path and all will be available in the viewer d %>% trelliscope(name = "city_vs_highway_mpg2", path = my_displays) # ordering the data frame will set default sort order of the display d %>% arrange(-mean_city_mpg) %>% trelliscope(name = "city_vs_highway_mpg") # tidyverse + ggplot2 mpg %>% nest(data = !one_of(c("manufacturer", "class"))) %>% mutate( panel = map_plot(data, ~ qplot(cty, hwy, data = .) + xlab("cty") + ylab("hwy") + xlim(7, 37) + ylim(9, 47) + theme_bw())) %>% trelliscope(name = "tidy_gg") # computing additional cognostics mpg_cog <- mpg %>% nest(data = !one_of(c("manufacturer", "class"))) %>% mutate( cogs = map_cog(data, ~ tibble( mean_city_mpg = mean(.$cty), mean_hwy_mpg = mean(.$hwy), most_common_drv = tail(names(table(.$drv)), 1) )) ) # computing additional cognostics explicitly using cog() # so we can specify descriptions, etc. mpg_cog2 <- mpg %>% nest(data = !one_of(c("manufacturer", "class"))) %>% mutate( cogs = map_cog(data, ~ tibble( mean_city_mpg = cog(mean(.$cty), desc = "Mean city mpg"), mean_hwy_mpg = cog(mean(.$hwy), desc = "Mean highway mpg"), most_common_drv = cog(tail(names(table(.$drv)), 1), desc = "Most common drive type") )), panel = map_plot(data, function(x) { plot_ly(data = x, x = ~cty, y = ~hwy, type = "scatter", mode = "markers") %>% layout( xaxis = list(range = c(9, 47)), yaxis = list(range = c(7, 37))) }) ) mpg_cog2 %>% trelliscope(name = "city_vs_highway_mpg", nrow = 1, ncol = 2) ## End(Not run)
Output and render functions for using trelliscopejs_widget within Shiny applications and interactive Rmd documents.
trelliscopeOutput(outputId, width = "100%", height = "400px") renderTrelliscope(expr, env = parent.frame(), quoted = FALSE)
trelliscopeOutput(outputId, width = "100%", height = "400px") renderTrelliscope(expr, env = parent.frame(), quoted = FALSE)
outputId |
output variable to read from |
width , height
|
Must be a valid CSS unit (like |
expr |
An expression that generates a trelliscopejs_widget |
env |
The environment in which to evaluate |
quoted |
Is |
Update Trelliscope app display list file
update_display_list(base_path, jsonp = TRUE)
update_display_list(base_path, jsonp = TRUE)
base_path |
the base directory of the trelliscope application |
jsonp |
should json for display list be jsonp (TRUE) or json (FALSE)? |
Construct a list of view items
view_item(name, hash)
view_item(name, hash)
name |
A string indicating the name of the view (will be displayed in the "Views" sidebar) |
hash |
A URL hash that sends the user to this view (typically the URL starting with &nrow=...) |
Construct a list of view items
view_list(...)
view_list(...)
... |
Objects created using |
Write cognostics data for a display in a Trelliscope app
write_cognostics(cogdf, base_path, id, name, group = "common", jsonp = TRUE)
write_cognostics(cogdf, base_path, id, name, group = "common", jsonp = TRUE)
cogdf |
a data frame of cognostics, prepared with |
base_path |
the base directory of the trelliscope application |
id |
a unique id for the application |
name |
name of the display |
group |
group that the display belongs to |
jsonp |
should json for cognostics be jsonp (TRUE) or json (FALSE)? |
Write Trelliscope app configuration file
write_config( base_path, id, self_contained = FALSE, jsonp = TRUE, require_token = FALSE, disclaimer = FALSE, split_layout = FALSE, has_legend = FALSE )
write_config( base_path, id, self_contained = FALSE, jsonp = TRUE, require_token = FALSE, disclaimer = FALSE, split_layout = FALSE, has_legend = FALSE )
base_path |
the base directory of the trelliscope application |
id |
a unique id for the application |
self_contained |
should the Trelliscope display be a self-contained html document? |
jsonp |
should json for app config be jsonp (TRUE) or json (FALSE)? |
require_token |
require a special token for all displays to be visible (experimental) |
disclaimer |
an optional string of html to include as a disclaimer for the set of displays |
split_layout |
boolean that determines if the layout is split into components like a facet_grid vs. individual panels like facet_wrap. Only applies to ggplot2 plot objects. |
has_legend |
should a legend be reported for split_layout |
Write a "display object" file for a Trelliscope app
write_display_obj( cogdf, panel_example, base_path, id, name, group = "common", desc = "", height = 500, width = 500, inputs = NULL, md_desc = "", state = NULL, google_analytics_id = NULL, views = NULL, jsonp = TRUE, split_sig = NULL, panel_img_col = NULL, self_contained = FALSE, thumb = TRUE, split_layout = FALSE, split_aspect = NULL, has_legend = FALSE, order = 1, pb = NULL )
write_display_obj( cogdf, panel_example, base_path, id, name, group = "common", desc = "", height = 500, width = 500, inputs = NULL, md_desc = "", state = NULL, google_analytics_id = NULL, views = NULL, jsonp = TRUE, split_sig = NULL, panel_img_col = NULL, self_contained = FALSE, thumb = TRUE, split_layout = FALSE, split_aspect = NULL, has_legend = FALSE, order = 1, pb = NULL )
cogdf |
a data frame of cognostics, prepared with |
panel_example |
an example object of one panel of a display (can be trellis, ggplot2, or htmlwidget object) |
base_path |
the base directory of the trelliscope application |
id |
a unique id for the application |
name |
name of the display |
group |
group that the display belongs to |
desc |
description of the display |
height |
height in pixels of each panel |
width |
width in pixels of each panel |
inputs |
optional set of input specifications (using |
md_desc |
optional string of markdown that will be shown in the viewer for additional context about the display |
state |
the initial state the display will open in |
google_analytics_id |
optional string specifying Google Analytics ID |
views |
an optional list of pre-specified views of the display (experimental) |
jsonp |
should json for display object be jsonp (TRUE) or json (FALSE)? |
split_sig |
optional string "signature" specifying the data splitting |
panel_img_col |
which column (if any) is a panel image column? |
self_contained |
should the Trelliscope display be a self-contained html document? |
thumb |
should a thumbnail be created? |
split_layout |
boolean that determines if the layout is split into components like a facet_grid vs. individual panels like facet_wrap. Only applies to ggplot2 plot objects. |
split_aspect |
list indicating aspect ratios of axes for a split layout. Only applies to ggplot2 plot objects. |
has_legend |
should a legend be reported for split_layout |
order |
an integer indicating the order that the display should appear in if using multiple displays |
pb |
optional progress bar object to pass in and use to report progress |
Write a plot object as a panel in a Trelliscope display
write_panel( plot_object, key, base_path, name, group = "common", width, height, jsonp = TRUE, split_layout = FALSE )
write_panel( plot_object, key, base_path, name, group = "common", width, height, jsonp = TRUE, split_layout = FALSE )
plot_object |
a plot object to be written (can be trellis, ggplot2, or htmlwidget) |
key |
a string identifying the panel key, which will be used as the panel file name and which the |
base_path |
the base directory of the trelliscope application |
name |
name of the display that the panel belongs to |
group |
group name of the display that the panel belongs to |
width |
width in pixels of each panel |
height |
height in pixels of each panel |
jsonp |
should json for panel be jsonp (TRUE) or json (FALSE)? |
split_layout |
boolean that determines if the layout is split into components like a facet_grid vs. individual panels like facet_wrap. Only applies to ggplot2 plot objects. |
Write a list of plot objects as panels in a Trelliscope display
write_panels(plot_list, ..., pb = NULL)
write_panels(plot_list, ..., pb = NULL)
plot_list |
a named list of plot objects to be written as panels (objects can be trellis, ggplot2, or htmlwidget) with the list names being the keys for the panels |
... |
params passed directly to |
pb |
optional progress bar object to pass in and use to report progress |