[英]Render Dynamic Equations in Shiny
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.如果我编织文档一切正常,直到我更改输入并显示 mathjax/latex 代码而不是正确的渲染方程。
A minimum working example is this ( test.Rmd
)一个最小的工作示例是这个(
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在我更改
A
或B
,我得到了这个
Any idea on how to solve this or what I did wrong?关于如何解决这个问题或我做错了什么的任何想法?
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)
A bit late, but I just figured a solution that works in RMarkdown:有点晚了,但我只是想出了一个适用于 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))
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.