Skip to content

Commit 740ee6c

Browse files
committed
fix MathJax path in orca(), improve docs
1 parent 194d435 commit 740ee6c

File tree

5 files changed

+24
-26
lines changed

5 files changed

+24
-26
lines changed

R/layout.R

+6-6
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,12 @@ rangeslider <- function(p, start = NULL, end = NULL, ...) {
9292
#' @param cloud include the send data to cloud button?
9393
#' @param locale locale to use. See [here](https://github.com/plotly/plotly.js/tree/master/dist#to-include-localization) for more info.
9494
#' @param mathjax add [MathJax rendering support](https://github.com/plotly/plotly.js/tree/master/dist#to-support-mathjax).
95-
#' If `cdn`, mathjax is loaded externally (meaning an internet connection is needed to
96-
#' view the graph). If `local`, mathjax must be available locally. IMPORTANT: plotly uses
97-
#' SVG-based mathjax rendering which doesn't play nicely with HTML-based rendering
98-
#' (e.g., rmarkdown documents). In this case, you may want to consider `<iframe>`-ing
99-
#' your plotly graph(s) into the larger document.
100-
#' See [here](https://github.com/ropensci/plotly/blob/master/inst/examples/rmd/MathJax/index.Rmd) for an example.
95+
#' If `"cdn"`, mathjax is loaded externally (meaning an internet connection is needed for
96+
#' TeX rendering). If `"local"`, the PLOTLY_MATHJAX_PATH environment variable must be
97+
#' set to the location (a local file path) of MathJax. IMPORTANT: plotly uses SVG-based
98+
#' mathjax rendering which doesn't play nicely with HTML-based rendering (e.g., rmarkdown documents).
99+
#' In this case, consider `<iframe>`-ing your plotly graph(s) into the larger document
100+
#' (see [here](https://github.com/ropensci/plotly/blob/master/inst/examples/rmd/MathJax/index.Rmd) for an example).
101101
#' @author Carson Sievert
102102
#' @export
103103
#' @examples

R/orca.R

+5-6
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@
1111
#' Applies to all output images.
1212
#' @param height Sets the image height. If not set, defaults to `layout.height` value.
1313
#' Applies to all output images.
14-
#' @param mathjax whether or not to specify a path to mathjax (required to export LaTeX characters).
15-
#' This should 'just work' in RStudio, but outside RStudio, you may have to set
16-
#' the PLOTLY_MATHJAX_PATH environment variable to the location of MathJax.
14+
#' @param mathjax whether or not to include MathJax (required to render [TeX]).
15+
#' If `TRUE`, the PLOTLY_MATHJAX_PATH environment variable must be set and point
16+
#' to the location of MathJax (this variable is also used to render [TeX] in
17+
#' interactive graphs, see [config]).
1718
#' @param parallel_limit Sets the limit of parallel tasks run.
1819
#' @param verbose Turn on verbose logging on stdout.
1920
#' @param debug Starts app in debug mode and turn on verbose logs on stdout.
@@ -25,9 +26,7 @@
2526
#'
2627
#' \dontrun{
2728
#' p <- plot_ly(z = ~volcano) %>% add_surface()
28-
#' orca(p, "surface-plot.png")
2929
#' orca(p, "surface-plot.svg")
30-
#' orca(p, "surface-plot.pdf")
3130
#' }
3231
#'
3332

@@ -65,7 +64,7 @@ orca <- function(p, file = "plot.png", format = tools::file_ext(file),
6564
if (!is.null(height)) args <- c(args, "--height", height)
6665
if (!is.null(parallel_limit)) args <- c(args, "--parallel-limit", parallel_limit)
6766
if (!is.na(mapbox_token())) args <- c(args, "--mapbox-access-token", mapbox_token())
68-
if (isTRUE(mathjax)) args <- c(args, "--mathjax", mathjax_path())
67+
if (isTRUE(mathjax)) args <- c(args, "--mathjax", file.path(mathjax_path(), "MathJax.js"))
6968

7069
# TODO: point to local topojson? Should this only work if plot_geo(standalone = TRUE)?
7170
try_library("processx", "orca")

inst/examples/rmd/MathJax/index.Rmd

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Some HTML-based MathJax:
77

88
$$ \alpha+\beta $$
99

10-
You _could_ print this this **plotly** graph with SVG-based rendering, but it would break the HTML-based rendering of **rmarkdown**!
10+
You _could_ print this **plotly** graph with SVG-based rendering, but it would break the HTML-based rendering of **rmarkdown**!
1111

1212
```{r message = FALSE}
1313
library(plotly)
@@ -17,13 +17,13 @@ p <- plotly_empty() %>%
1717
config(mathjax = "cdn")
1818
```
1919

20-
Instead, use something like the **widgetframe** package to create a responsive iframe. This ensures the SVG-based rendering that plotly requires is done in isolation (i.e., independent of **rmarkdown**'s HTML-based rendering).
20+
Instead, use something like the **widgetframe** package to create a responsive iframe which ensure the SVG-based rendering that plotly requires is done independently of **rmarkdown**'s HTML-based rendering.
2121

2222
```{r}
2323
widgetframe::frameableWidget(p)
2424
```
2525

26-
Or, do it the old-fashioned way by saving your plotly graph to an HTML file and use an HTML `<iframe>` to
26+
Or, do it the old-fashioned way: save your plotly graph to an HTML file via `htmlwidgets::saveWidget()` then use an HTML `<iframe>`
2727

2828
```{r}
2929
htmlwidgets::saveWidget(p, "my-plotly-plot.html")

man/config.Rd

+6-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/orca.Rd

+4-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)