响应输入更改后 withMathJax 格式丢失

withMathJax format lost after reactive input changed

示例代码:

ui <- fluidPage(

  withMathJax(),
  tags$div(HTML("<script type='text/x-mathjax-config'>
                MathJax.Hub.Config({
                tex2jax: {inlineMath: [['$','$'], ['\(','\)']]}
                });
                </script>
                ")),

    sidebarPanel(sliderInput("k", "(k_{test})", value=2, min=1, max=3)),

    mainPanel(uiOutput("out"))
)

server <- function(input, output, session){
  output$out <- renderUI({ paste("(k_{test}=)", input$k)}) 
}

shinyApp(ui, server)

这是我的问题: 最初,该应用程序运行良好。但是,当更改滑块上的输入时,输出方程会丢失其格式,我不知道如何解决这个问题。

提前致谢!

?withMathJax

说:

It only needs to be called once in an app unless the content is rendered after the page is loaded, e.g. via renderUI, in which case we have to call it explicitly every time we write math expressions to the output.

output$out <- renderUI({ 
  list(
    withMathJax(),
    paste("(k_{test}=)", input$k)
  )
}) 

应该可以解决您的问题