如何在R Shiny应用程序中左对齐LaTeX公式?

3

我正在开发一款闪亮的应用程序。我使用 withMathJax() 插入了一个方程式。我想让方程式左对齐并将字体更改为 "Arial"。有人可以帮忙吗?

以下是示例问题:

library(shiny)


ui  <- fluidPage(
  titlePanel("hello"),
  sidebarLayout(
    sidebarPanel(),
    mainPanel(
      uiOutput("formula")
    )
  )
)

server <- function(input,output){
   output$formula <- renderUI({
    listcat <- c("Men","Ladies")
   value <- 15
    withMathJax(paste0("$$\\frac{",listcat[1], "\\cap ", listcat[2],"}{",listcat[1],"} =", value,"$$"))
  })
} 
1个回答

4
您可以使用CSS来对齐公式:
div.MathJax_Display{
   text-align: left !important;
}

注意: 使用!important来确保参数不会被覆盖。
然后使用。
tags$head(tags$style(HTML("...")))

将其插入Shiny应用程序中。

可重现的示例:

library(shiny)

ui <- fluidPage(
  titlePanel("hello"),
  tags$head(
    tags$style(HTML("
                    div.MathJax_Display{
                    text-align: left !important;
                    }
  "))
  ),
  sidebarLayout(
    sidebarPanel(),
    mainPanel(
      uiOutput("formula")
    )
  )
)

server <- function(input,output){
  output$formula <- renderUI({
    listcat <- c("Men","Ladies")
    value <- 15
    withMathJax(paste0("$$\\frac{",listcat[1], "\\cap ", listcat[2],"}{",listcat[1],"} =", value,"$$"))
  })
} 

shinyApp(ui, server)

请注意,MathJax不支持Arial字体,请参见此处:http://docs.mathjax.org/en/latest/font-support.html

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接