繁体   English   中英

如何在 R Shiny 应用程序中左对齐乳胶方程?

[英]How to left align latex equation in R Shiny app?

我正在开发一个闪亮的应用程序。 我已经使用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,"$$"))
  })
} 

您可以使用 CSS 来对齐公式:

div.MathJax_Display{
   text-align: left !important;
}

注意:使用!important确保参数不被覆盖

然后使用

tags$head(tags$style(HTML("...")))

将其插入闪亮的应用程序。

可重现的例子:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM