【问题标题】:Mathjax in a shinyBS alert闪亮BS警报中的Mathjax
【发布时间】:2017-10-04 06:24:09
【问题描述】:

有没有办法在shinyBS 创建的警报中使用 MathJax?下面的尝试没有按预期工作。

library(shiny)
library(shinyBS)
shinyApp(
  ui =
    fluidPage(
      sidebarLayout(
        sidebarPanel(textInput("num1", NULL, value = 100),
                     "divided by", textInput("num2", NULL, value = 20),
                     "equals", textOutput("exampleOutput")),
        mainPanel(
          withMathJax(bsAlert("alert"))
        )
      )
    ),
  server =
    function(input, output, session) {
      output$exampleOutput <- renderText({
        num1 <- as.numeric(input$num1)
        num2 <- as.numeric(input$num2)

        if(num2 == 0) {
          createAlert(session, "alert", "exampleAlert", title = "Oops",
                      content = HTML("You cannot divide by <span class='math inline'>\\(0\\)</span>."))
        } else {
          closeAlert(session, "exampleAlert")
          return(num1/num2)
        }

      })
    }
)

【问题讨论】:

    标签: r shiny shinybs


    【解决方案1】:

    这适用于withMathJax(bsAlert("alert")),就像在 OP 中一样

    content = "You cannot divide by <span class='math inline'>\\(0\\)</span>.<script>if (window.MathJax) MathJax.Hub.Queue(['Typeset', MathJax.Hub]);</script>"
    

    奇怪,因为脚本被包含了两次。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-02-27
      • 1970-01-01
      • 1970-01-01
      • 2015-04-19
      • 2018-09-16
      • 1970-01-01
      • 2016-05-01
      • 2018-12-06
      相关资源
      最近更新 更多