【问题标题】:How to left align latex equation in R Shiny app?如何在 R Shiny 应用程序中左对齐乳胶方程?
【发布时间】:2019-09-14 20:49:20
【问题描述】:

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


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2023-03-26
      • 2016-02-03
      • 2021-02-19
      • 2010-12-21
      • 2014-09-01
      • 1970-01-01
      • 2018-11-06
      • 1970-01-01
      • 2019-10-07
      相关资源
      最近更新 更多