乳胶在闪亮的selectInput

问题描述 投票:1回答:2

我想知道是否有人知道如何在Shiny selectInput()命令中包含LaTeX代码。我想做点什么:

ui <- shinyUI(
  fluidPage(
       selectInput(
        c("$\mu_0 \leq 3$" = "less",
          "$\mu_0 \geq 3" = "more",
          "$\mu_0 = 3" = "equal"
        )
    )
)

server <- function(input, output, session){  
      # server side code here...
}

shinyApp(ui = ui, server = server)
r shiny latex
2个回答
1
投票

你可以使用katex。

library(shiny)

choices <- c("less", "more", "equal")
choicesNames <- c("\\\\\\mu_0 \\leq 3", 
                  "\\\\\\mu_0 \\geq 3",
                  "\\\\\\mu_0 = 3")
choices <- setNames(choices, choicesNames)

ui <- shinyUI(
  fluidPage(
    tags$head(
      tags$link(rel="stylesheet", 
                href="https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.css", integrity="sha384-9tPv11A+glH/on/wEu99NVwDPwkMQESOocs/ZGXPoIiLE8MU/qkqUcZ3zzL+6DuH", 
                crossorigin="anonymous"),
      tags$script(src="https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.js", integrity="sha384-U8Vrjwb8fuHMt6ewaCy8uqeUXv4oitYACKdB0VziCerzt011iQ/0TqlSlv8MReCm", 
                  crossorigin="anonymous")
    ),
    selectizeInput(
      "ID", 
      "LABEL", 
      choices,
      options = list(render = I("
    {
      item: function(item, escape) { 
              var html = katex.renderToString(item.label);
              return '<div>' + html + '</div>'; 
            },
      option: function(item, escape) { 
                var html = katex.renderToString(item.label);
                return '<div>' + html + '</div>'; 
              }
    }"))
    )
  )
)

server <- function(input, output, session){  
    # server side code here...
}

shinyApp(ui = ui, server = server)

enter image description here


0
投票

这样的事情对你有帮助吗?

selectInput("mean", label = "Parameter", choices=c("\u03BC"="mu"))
© www.soinside.com 2019 - 2024. All rights reserved.