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

时间:2019-04-25 12:07:50

标签: css r shiny mathjax

我正在开发一个闪亮的应用程序。我使用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 个答案:

答案 0 :(得分:2)

您可以使用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

相关问题