Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I add symbols in slider labels?

Tags:

r

shiny

I'm trying to add symbols and math expressions to slider labels, e.g. instead of "Choose lambda:" I want the label to read "Choose λ:". I've tried multiple variations of HTML and expression(), such as:

sliderInput ("lambda1", label=HTML("Choose &-lambda;:"), min=0, max=10, value=1.1, step=0.1) 

with the hyphen removed (I put it there to defeat formatting in this editor).

and:

sliderInput("lambda1", label=expression(lambda), min=0, max=10, value=1.1, step=0.1).

In all cases the label displays as "Choose &-lambda;:" (without hyphen) rather than "Choose λ:".

I also need subscripts and superscripts, but haven't tried any code yet. I presume that if I can get HTML symbols, I'll be able to format subscripts and such with the appropriate tags.

Edit
Sorry, I can't answer myself because I'm a new user. I found an answer to the Greek symbols part of the question. It's ironic, because I've been beating my head against this problem for a week, then an hour after posting the question on SO I figured it out. D'oh!

Enclose the HTML() function with div(HTML()). Thusly:

sliderInput ("lambda1", label=div(HTML("Choose &-lambda;:")), min=0, max=10, value=1.1, step=0.1),

again without the hyphen in &-lambda;.

That worked!

like image 822
Mike C. Avatar asked Feb 07 '14 01:02

Mike C.


1 Answers

This is a bug reported here, and has been fixed in the development version of shiny. HTML() should work with the sliderInput() labels in shiny >= 0.9.0.

like image 63
Yihui Xie Avatar answered Oct 29 '22 07:10

Yihui Xie