打印$ \ sigma $为Shiny,而不是$$ \ sigma $$

时间:2019-07-25 11:14:47

标签: r shiny

我要打印TeX脚本$\simga$,而不是$$\sigma$$。但是,当我使用$\simga$而不是$$\sigma$$时,以下代码不起作用。

在以下代码中,请执行两次,第一次使用$\simga$,第二次使用$$\sigma$$

library(shiny)

# Define UI for application 
ui <- fluidPage(

    # Application title
    titlePanel("Old Faithful Geyser Data"),

    # Sidebar with a slider input for number of bins 
    sidebarLayout(
        sidebarPanel(
            sliderInput("bins",
                        "Number of bins:",
                        min = 1,
                        max = 50,
                        value = 30)
        ),

        # Show a  TeX
        mainPanel(
            shiny::uiOutput("formula")
        )
    )
)

# Define server  
server <- function(input, output) {

    output$formula <- renderUI({

        # s<-"$\\sigma$" This is not functional, why???????

        s<-"$$\\sigma$$"
        withMathJax(s)        

    })

}

# Run the application 
shinyApp(ui = ui, server = server)

输出如下: enter image description here


编辑答案

确实可行,谢谢@Henryk Gerlach!

library(shiny)

# Define UI for application 
ui <- fluidPage(

    # Application title
    titlePanel("Old Faithful Geyser Data"),

    # Sidebar with a slider input for number of bins 
    sidebarLayout(
        sidebarPanel(
            sliderInput("bins",
                        "Number of bins:",
                        min = 1,
                        max = 50,
                        value = 30)
        ),

        # Show a  TeX
        mainPanel(
            shiny::uiOutput("formula")
        )
    )
)

# Define server  
server <- function(input, output) {

    output$formula <- renderUI({

        # s<-"$\\sigma$" This is not functional, why???????

        s<-'\\( \\sigma \\) \\( \\sigma \\) \\( \\sigma \\)'
        withMathJax(s)        

    })

}

# Run the application 
shinyApp(ui = ui, server = server)

由于单币种不是以新行开头,因此正是单币种。谢谢@Henryk Gerlach,...很棒。

enter image description here

1 个答案:

答案 0 :(得分:1)

默认情况下,这取决于配置的delimiter

s<-'\\( \\sigma \\)'

应该工作。