LaTeX formula in Shiny panel

♀尐吖头ヾ 提交于 2019-12-10 02:02:03

问题


I want to display a -LaTeX formated- formula in a Shiny panel, but I can't find a way to combine textOutput with withMathJax. I tried the following but it didn't work. Any help would be gratefully appreciated.

--ui.r

...
    tabPanel("Diagnostics", h4(textOutput("diagTitle")),
withMathJax(textOutput("formula")),
),
...

--server.r

...
output$formula <- renderText({
    print(paste0("Use this formula: $$\\hat{A}_{\\small{\\textrm{M€}}} =", my_calculated_value,"$$"))
})
...

回答1:


ui.R

tabPanel("Diagnostics", h4(textOutput("diagTitle")),
    withMathJax(uiOutput("formula")),
)

server.R

output$formula <- renderUI({
    return(HTML(paste0("<p>,"Use this formula: $$\\hat{A}_{\\small{\\textrm{M€}}} =", my_calculated_value,"$$","</p>")))
})



回答2:


Use uiOutput on the UI side and renderUI on the server side for dynamic content.

ui <- fluidPage(
  withMathJax(),
  tabPanel(
    title = "Diagnostics", 
    h4(textOutput("diagTitle")),
    uiOutput("formula")
  )
)

server <- function(input, output, session){
  output$formula <- renderUI({
    my_calculated_value <- 5
    withMathJax(paste0("Use this formula: $$\\hat{A}_{\\small{\\textrm{M€}}} =", my_calculated_value,"$$"))
  })
}

shinyApp(ui, server)

More examples: http://shiny.leg.ufpr.br/daniel/019-mathjax/




回答3:


How about using renderPrint()?

Minimal working example:

library(shiny)

server <- function(input, output, session) {

 output$formula <- renderPrint({
     print(paste0("Use this formula: $$\\hat{A}_{\\small{\\textrm{M€}}} =", 1,"$$"))
})

}

ui <- fluidPage(


  titlePanel("Hello Shiny!"),


  sidebarLayout(
    sidebarPanel(

    ),

    mainPanel(
      withMathJax(textOutput("formula"))
    )
    )
)

shinyApp(ui = ui, server = server)

EDIT: To me it looks like this:



来源:https://stackoverflow.com/questions/30169101/latex-formula-in-shiny-panel

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!