2017-09-15 4 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)