Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display symbols in browser via shiny package R

Tags:

symbols

r

shiny

I have the following numeric input in my shiny app:

numericInput(
 inputId = "beta",
 label = "beta:",
 value = 0.05,
 step = 0.01
),

Is it possible to display in web browser "beta" as Greek symbol instead of string "beta"?

Thanks in advance.

like image 700
dmitry Avatar asked Dec 19 '13 06:12

dmitry


1 Answers

The following works for me:

numericInput(
  inputId = "beta",
  label = HTML("β:"),
  value = 0.05,
  step = 0.01
)

so replace beta by β and it should render in the browser as β. HTML is used to mark the text so shiny doesnt performing escaping.

EDIT: to carry out more involved operations mathjax is useful. Here is an example of a ui.R calling the MathJax library:

library(shiny)

shinyUI(pageWithSidebar(

  # Application title
  headerPanel("New Application"),
  # Sidebar with a slider input for number of observations
  sidebarPanel(
    tags$head( tags$script(src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML-full", type = 'text/javascript'),
               tags$script( "MathJax.Hub.Config({tex2jax: {inlineMath: [['$','$'], ['\\(','\\)']]}});", type='text/x-mathjax-config')
    ),
    numericInput(
      inputId = "beta",
      label = HTML("$$ \\beta_1 $$"),
      value = 0.05,
      step = 0.01
    )
  ),
  # Show a plot of the generated distribution
  mainPanel(
    plotOutput("distPlot")
  )
))
like image 66
jdharrison Avatar answered Nov 18 '22 03:11

jdharrison