Repository navigation
Expand file tree
/
Copy pathdev.R
More file actions
56 lines (51 loc) · 1.54 KB
/
Copy pathdev.R
File metadata and controls
56 lines (51 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#' Inspect JSON sent to plotly.js
#'
#' This function is useful for obtaining/viewing/debugging JSON
#' sent to plotly.js.
#'
#' @param p a plotly or ggplot object.
#' @param jsonedit use `listviewer::jsonedit` to view the JSON?
#' @param ... other options passed onto `listviewer::jsonedit`
#' @export
#' @examples
#'
#' plotly_json(plot_ly())
#' plotly_json(plot_ly(), FALSE)
plotly_json <- function(p = last_plot(), jsonedit = interactive(), ...) {
plotlyJSON <- to_JSON(plotly_build(p)$x, pretty = TRUE)
if (jsonedit) {
try_library("listviewer", "plotly_json")
listviewer::jsonedit(plotlyJSON, mode = "form", ...)
} else {
plotlyJSON
}
}
#' Acquire (and optionally display) plotly's plot schema
#'
#' The schema contains valid attributes names, their value type,
#' default values (if any), and min/max values (if applicable).
#'
#' @param jsonedit use `listviewer::jsonedit` to view the JSON?
#' @param ... other options passed onto `listviewer::jsonedit`
#' @export
#' @examples
#' s <- schema()
#'
#' # retrieve acceptable `layout.mapbox.style` values
#' if (!is.na(Sys.getenv('MAPBOX_TOKEN', NA))) {
#' styles <- s$layout$layoutAttributes$mapbox$style$values
#' subplot(
#' plot_mapbox() %>% layout(mapbox = list(style = styles[3])),
#' plot_mapbox() %>% layout(mapbox = list(style = styles[5]))
#' )
#' }
#'
#'
#'
schema <- function(jsonedit = interactive(), ...) {
if (jsonedit) {
try_library("listviewer", "schema")
print(listviewer::jsonedit(Schema, mode = "form"))
}
invisible(Schema)
}