Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display LaTeX equations in a shiny dashboard app in R

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: enter image description here 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:enter image description here

but when clicked on theory I get correctly rendered equations: enter image description here

Is there a way to fix this? Many thanks!

like image 923
Sölvi Avatar asked Aug 19 '15 16:08

Sölvi


1 Answers

It is also possible to wrap includeMarkdown() in withMathJax(), so you won't need to change your .md-file:

withMathJax(includeMarkdown("Theory.md"))
like image 163
michael Avatar answered Nov 04 '22 06:11

michael