Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LaTeX formula in Shiny panel

Tags:

r

mathjax

shiny

I want to display a -LaTeX formated- formula in a Shiny panel, but I can't find a way to combine textOutput with withMathJax. I tried the following but it didn't work. Any help would be gratefully appreciated.

--ui.r

...
    tabPanel("Diagnostics", h4(textOutput("diagTitle")),
withMathJax(textOutput("formula")),
),
...

--server.r

...
output$formula <- renderText({
    print(paste0("Use this formula: $$\\hat{A}_{\\small{\\textrm{M€}}} =", my_calculated_value,"$$"))
})
...
like image 851
George Dontas Avatar asked May 11 '15 13:05

George Dontas


People also ask

Can I use latex to display math equations in shiny?

I’ve been working on a Shiny app and wanted to display some math equations. It’s possible to use LaTeX to show math using MathJax, as shown in this example from the makers of Shiny. However, by default, MathJax does not allow in-line equations, because the dollar sign is used so frequently. But I needed to use in-line math in my application.

How do you write equations in latex?

Writing basic equations in LaTeX is straightforward, for example: \documentclass{ article } \begin{ document } The well known Pythagorean theorem \ (x^2 + y^2 = z^2\) was proved to be invalid for other exponents. Meaning the next equation has no integer solutions: \ [ x^n + y^n = z^n \] \end{ document }

How do I write the summation symbol in latex?

It is very easy to produce the summation symbol (capital sigma) inside LaTeX’s math mode using the command \sum. The limits of the sum are then written using the common symbols for subscripts _ and superscripts ^ ( check this post ). For example, the previous equation was written with the code:

What is the application layout guide for shiny?

Application layout guide. Overview. Shiny includes a number of facilities for laying out the components of an application. This guide describes the following application layout features: The simple default layout with a sidebar for inputs and a large main area for output. Custom application layouts using the Shiny grid layout system.


1 Answers

Use uiOutput on the UI side and renderUI on the server side for dynamic content.

ui <- fluidPage(
  withMathJax(),
  tabPanel(
    title = "Diagnostics", 
    h4(textOutput("diagTitle")),
    uiOutput("formula")
  )
)

server <- function(input, output, session){
  output$formula <- renderUI({
    my_calculated_value <- 5
    withMathJax(paste0("Use this formula: $$\\hat{A}_{\\small{\\textrm{M€}}} =", my_calculated_value,"$$"))
  })
}

shinyApp(ui, server)

More examples: http://shiny.leg.ufpr.br/daniel/019-mathjax/

like image 146
GyD Avatar answered Oct 19 '22 20:10

GyD