2017-09-15 160 views
0

我有一個閃亮的文件,應該解釋一些數學和計算給出一些閃亮的輸入結果。在閃亮的渲染動態方程

如果我編織文檔一切正常,直到我改變輸入,並顯示mathjax/latex代碼而不是正確的渲染方程。

最低工作的例子是,(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) 
})) 
``` 

我期望看到的是這樣的(我才把我更改輸入)

Correct Picture

我改變A後或B,我得到這個

Broken Picture

任何想法如何解決這個問題或我做錯了什麼?

回答

1

這是一個工作示例。 確保您在瀏覽器中看到此內容。

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)