I would like to display an Rmd file with LaTeX equations in my shiny dashboard app. I've run into problems using includeMarkdown()
and includeHTML()
. Here is a simplified app of what I'm trying to achieve. Here is my app.R:
library(shinydashboard)
ui <- dashboardPage(
dashboardHeader(title='My test application'),
dashboardSidebar(
sidebarMenu(
menuItem("Theory", tabName = "theory", icon = icon("book"))
)
),
dashboardBody(
tabItems(
tabItem(tabName="theory",
includeMarkdown("Theory.Rmd")
#includeMarkdown("Theory.md")
#includeHTML("Theory.html")
)
)
)
)
server <- function(input, output){
}
shinyApp(ui = ui, server = server)
My Theory.Rmd file:
---
title: "Theory"
output:
html_document:
mathjax: "http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"
---
Here is an equation:
$$Q = a(h − c)^b$$
Note that in order to run the app, Theory.Rmd and app.R have to be saved in the same directory (e.g. the working directory) hand have to have those exact names. To obtain a markdown Theory.md file of the Rmd file, simply do:
library(knitr)
knit("Theory.Rmd","Theory.md")
And to obtain the Theory.html
file, simply press the Knit to HTML button in the Theory.Rmd file
When running my app in my browser or RStudio window, includeMarkdown("Theory.Rmd")
or includeMarkdown("Theory.md")
, do not render the equations but it starts by default in the theory menu item, like this:
However using includeHTML("Theory.html")
the equations render correctly but the screen display is shortened, and by default it does not start in any menu item, like this:
but when clicked on theory I get correctly rendered equations:
Is there a way to fix this? Many thanks!
It is also possible to wrap includeMarkdown()
in withMathJax()
, so you won't need to change your .md
-file:
withMathJax(includeMarkdown("Theory.md"))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With