Render plotly MathJax inside rmarkdown

Some HTML-based MathJax:

$$ \alpha+\beta $$

You could print this plotly graph with SVG-based rendering, but it would break the HTML-based rendering of rmarkdown!


p <- plotly_empty() %>%
  add_trace(x = 1, y = 1, text = TeX("\\alpha"), mode = "text", size = I(1000)) %>%
  config(mathjax = "cdn")

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.


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

htmlwidgets::saveWidget(p, "my-plotly-plot.html")

Try the plotly package in your browser

Any scripts or data that you put into this service are public.

plotly documentation built on Nov. 10, 2022, 5:42 p.m.