Reputation: 10222
I have a shiny-document that should explain some maths and calculate the result given some shiny-inputs.
If I knit the document everything works until I change an input and the mathjax/latex code is shown instead of the proper rendered equations.
A minimum working example is this (test.Rmd
)
---
output: html_document
runtime: shiny
---
```{r,,echo=F}
library(shiny)
```
```{r,echo=F}
numericInput("a", "A", value = 100, min = 0, max = 10000)
numericInput("b", "B", value = 120, min = 0, max = 10000)
a <- reactive(input$a)
b <- reactive(input$b)
renderText(withMathJax({
formula <- "$$
\\begin{split}
A &= %.0f \\\\
B &= %.0f
\\end{split}
$$"
text <- sprintf(formula, a(), b())
return(text)
}))
```
What I expect to see is this (which I get before I change an input)
after I change A
or B
, I get this
Any idea on how to solve this or what I did wrong?
Upvotes: 0
Views: 1387
Reputation: 31
A bit late, but I just figured a solution that works in RMarkdown:
library(shiny)
numericInput("a", "A", value = 100, min = 0, max = 10000)
numericInput("b", "B", value = 120, min = 0, max = 10000)
a <- reactive(input$a)
b <- reactive(input$b)
renderUI(
{
formula <- "$$
\\begin{split}
A &= %.0f \\\\
B &= %.0f
\\end{split}
$$"
text <- sprintf(formula, a(), b())
withMathJax(helpText(text))
})
Upvotes: 1
Reputation: 6750
Here is a working example. Make sure you see this on a browser.
library(shiny)
ui <- list(
numericInput("a", "A", value = 100, min = 0, max = 10000),
numericInput("b", "B", value = 120, min = 0, max = 10000),
uiOutput('out')
)
server <- function(input, output)
{
a <- reactive(input$a)
b <- reactive(input$b)
output$out <- renderUI({
formula <- "$$
\\begin{split}
A &= %.0f \\\\
B &= %.0f
\\end{split}
$$"
text <- sprintf(formula, a(), b())
withMathJax(
tags$p(text)
)
})
}
shinyApp(ui, server)
Upvotes: 1