Skip to content

Commit bbbea57

Browse files
committed
make sure to mention rendering plotly MathJax with shiny MathJax
1 parent bf5a1e9 commit bbbea57

File tree

4 files changed

+72
-19
lines changed

4 files changed

+72
-19
lines changed

NEWS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
### Other improvements relevant for all **plotly** objects
1717

18-
* TeX rendering via MathJax is now supported (#375). Use the new `mathjax` argument in `config()` to specify either external (`mathjax="cdn"`) or local (`mathjax="local"`) MathJaX. If `"cdn"`, mathjax is loaded externally (meaning an internet connection is needed for TeX rendering). If `"local"`, the PLOTLY_MATHJAX_PATH environment variable must be set to the location (a local file path) of MathJax. IMPORTANT: **plotly** uses SVG-based mathjax rendering which doesn't play nicely with HTML-based rendering (e.g., rmarkdown documents). In this case, consider `<iframe>`-ing your plotly graph(s) into the larger document (see [here](https://github.com/ropensci/plotly/blob/master/inst/examples/rmd/MathJax/index.Rmd) for an example).
18+
* LaTeX rendering via MathJax is now supported and the new `TeX()` function may be used to flag a character vector as LaTeX (#375). Use the new `mathjax` argument in `config()` to specify either external (`mathjax="cdn"`) or local (`mathjax="local"`) MathJaX. If `"cdn"`, mathjax is loaded externally (meaning an internet connection is needed for TeX rendering). If `"local"`, the PLOTLY_MATHJAX_PATH environment variable must be set to the location (a local file path) of MathJax. IMPORTANT: **plotly** uses SVG-based mathjax rendering which doesn't play nicely with HTML-based rendering (e.g., **rmarkdown** documents and **shiny** apps). To leverage both types of rendering, you must `<iframe>` your plotly graph(s) into the larger document (see [here](https://github.com/ropensci/plotly/blob/master/inst/examples/rmd/MathJax/index.Rmd) for an **rmarkdown** example and [here](https://github.com/ropensci/plotly/blob/master/inst/examples/rmd/MathJax/index.Rmd) for a **shiny** example).
1919
* The selection (i.e., linked-brushing) mode can now switch from 'transient' to 'persistent' by holding the 'shift' key. It's still possible to _force_ persistent selection by setting `persistent = TRUE` in `highlight()`, but `persistent = FALSE` (the default) is now recommended since it allows one to switch between [persistent/transient selection](https://plotly-book.cpsievert.me/linking-views-without-shiny.html#transient-versus-persistent-selection) in the browser, rather than at the command line.
2020
* The `highlight()` function gains a `debounce` argument for throttling the rate at which `on` events may be fired. This is mainly useful for improving user experience when `highlight(on = "plotly_hover")` and mousing over relevant markers at a rapid rate (#1277)
2121
* The new `partial_bundle()` function makes it easy to leverage [partial bundles of plotly.js](https://github.com/plotly/plotly.js#partial-bundles) for reduced file sizes and faster render times.

R/layout.R

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -94,19 +94,17 @@ rangeslider <- function(p, start = NULL, end = NULL, ...) {
9494
#' @param mathjax add [MathJax rendering support](https://github.com/plotly/plotly.js/tree/master/dist#to-support-mathjax).
9595
#' If `"cdn"`, mathjax is loaded externally (meaning an internet connection is needed for
9696
#' 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).
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
99+
#' (e.g., **rmarkdown** documents and **shiny** apps). To leverage both types of rendering,
100+
#' you must `<iframe>` your plotly graph(s) into the larger document
101+
#' (see [here](https://github.com/ropensci/plotly/blob/master/inst/examples/rmd/MathJax/index.Rmd)
102+
#' for an **rmarkdown** example and
103+
#' [here](https://github.com/ropensci/plotly/blob/master/inst/examples/rmd/MathJax/index.Rmd) for a **shiny** example).
101104
#' @author Carson Sievert
102105
#' @export
103106
#' @examples
104107
#'
105-
#' today <- Sys.Date()
106-
#' x <- seq.Date(today, today + 360, by = "day")
107-
#' p <- plot_ly(x = x, y = rnorm(length(x))) %>%
108-
#' add_lines()
109-
#'
110108
#' # remove the plotly logo and collaborate button from modebar
111109
#' config(p, displaylogo = FALSE, collaborate = FALSE)
112110
#'
@@ -116,6 +114,13 @@ rangeslider <- function(p, start = NULL, end = NULL, ...) {
116114
#' layout(title = TeX("\\text{Some mathjax: }\\alpha+\\beta x")) %>%
117115
#' config(mathjax = "cdn")
118116
#'
117+
#' # change the language used to render date axes and on-graph text
118+
#' # (e.g., modebar buttons)
119+
#' today <- Sys.Date()
120+
#' x <- seq.Date(today, today + 360, by = "day")
121+
#' p <- plot_ly(x = x, y = rnorm(length(x))) %>%
122+
#' add_lines()
123+
#'
119124
#' # japanese
120125
#' config(p, locale = "ja")
121126
#' # german

inst/examples/shiny/MathJax/app.R

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Example of rendering both plotly's (SVG) MathJax inside a
2+
# shiny app with it's own (HTML) MathJax. This currently requires
3+
# bringing in the plotly graph with an iframe
4+
library(shiny)
5+
library(plotly)
6+
library(htmlwidgets)
7+
library(htmltools)
8+
9+
addResourcePath("tmp", tempdir())
10+
f <- tempfile(fileext = ".html")
11+
12+
ui <- fluidPage(
13+
withMathJax(helpText('Dynamic output 1: $$\\alpha^2$$')),
14+
uiOutput("p")
15+
)
16+
17+
server <- function(input, output, ...) {
18+
19+
output$p <- renderUI({
20+
21+
plot_ly() %>%
22+
add_lines(x = zoo::index(co2), y = co2) %>%
23+
layout(
24+
title = TeX("CO_2 \\text{measured in } \\frac{parts}{million}"),
25+
xaxis = list(title = "Time"),
26+
yaxis = list(title = TeX("\\text{Atmospheric concentraion of CO}_2"))
27+
) %>%
28+
config(mathjax = "cdn") %>%
29+
saveWidget(f)
30+
31+
tags$iframe(
32+
src = file.path("tmp", basename(f)),
33+
width = "100%",
34+
height = "400",
35+
scrolling = "no",
36+
seamless = "seamless",
37+
frameBorder = "0"
38+
)
39+
})
40+
41+
}
42+
43+
shinyApp(ui, server)

man/config.Rd

Lines changed: 14 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)