MathJax equations in Shiny app rendering locally, but break when deployed to Shinyapps.io

207 Views Asked by At

Here's a Shiny app that renders a LaTeX equation with MathJax. When this app is run locally, all three equations are rendered (for testing purposes, these are equations within a renderTable, a renderText and simply p).

However, when deployed to Shinyapps.io, the only rendered equation is the one called in the p tag.

library(shiny)

eq <- "$$ \\frac{numerator}{denominator} \\!$$"

ui <- {
    fluidPage(
        withMathJax(),
        # simple tableOutput - not rendered
        tableOutput('table'),
        
        # simple textOutput - not rendered
        textOutput('text'),
        
        # no actual rendering required - works properly
        p(eq)
    )
}

server <- function(input, output, session) {

    output$text <- renderText(eq)
    
    output$table <- renderTable({
        data.frame(
            v1 = 'simple equation',
            v2 = eq)
    })
}

shinyApp(ui, server)

The fact that the equation in the p tag renders properly seems to rule out the idea that there's some issue with the GET requests to the server for the MathJax Javascript (you can see the requests go through).

I've also removed cached data from the browser locally (tested on Firefox and Chrome), and the equations still render fine.

Interestingly, inspecting the local version shows the relevant HTML elements (e.g., td for the table) wrapped in a <div class='MathJax_Display'>, whereas this div is not found in the Shinyapps.io version.

There are no issues that pop up in the logs; here is the log info (note R version; I haven't been able to test on R 4.0.2 yet):

  • Server version: 1.8.4.1-20
  • LANG: en_US.UTF-8
  • R version: 3.6.0
  • shiny version: 1.5.0
  • rmarkdown version: (none)
  • httpuv version: 1.5.4
  • knitr version: (none)
  • jsonlite version: 1.7.0
  • RJSONIO version: (none)
  • htmltools version: 0.5.0
  • Using pandoc: /opt/connect/ext/pandoc2
  • Using jsonlite for JSON processing
0

There are 0 best solutions below