R 与 mathjax 条件案例一起闪亮

Cyr*_*_44 5 r conditional-statements mathjax shiny

您好,我知道您可以使用该withMathJax函数在 R-shiny 应用程序中创建内联方程,但从我所见,您可以使用简单的数学方程,就像此处的Rshiny 示例一样。我想知道是否有任何一种新的方法添加条件情况,就像在乳胶中使用以下代码一样

f(n) =
\begin{cases}
n/2,  & \text{if $n$ is even} \\
3n+1, & \text{if $n$ is odd}
\end{cases}
Run Code Online (Sandbox Code Playgroud)

这会产生以下内容,欢呼

条件输出

SeG*_*eGa 2

我想这就是你想要的,或者?

library(shiny)

ui <- {fluidPage(
  title = 'MathJax Examples',
  withMathJax(),
  uiOutput('ex4')
  )}

server <- function(input, output, session) {
  output$ex4 <- renderUI({
    withMathJax(
      helpText('$$f(n)=\\begin{cases}
               n/2,  & \\text{if $n$ is even} \\\\
               3n+1, & \\text{if $n$ is odd}
               \\end{cases}\\!$$'))
  })
}
shinyApp(ui, server)
Run Code Online (Sandbox Code Playgroud)