Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Formatting number output of sliderInput in shiny

Tags:

A good example of my question is found in the Movie Review example in the Shiny Gallery here:

http://shiny.rstudio.com/gallery/movie-explorer.html

There is a slider on the left hand side panel called "Year Released" which ranges between 1940 and 2014. Here is the code for it from the ui.R

sliderInput("year", "Year released", 1940, 2014, value = c(1970, 2014))

You will notice that the formatting of the years when you use the slider are of the form:

"1,940" "2,014" with a comma separating the first digit from the last three.

I know that one can use dateRangeInputin Shiny but this requires the variable to be in a date format. For data variables that are simply numbers referring to years such as this example, is there a simple way to format the number output to remove the comma? I can't seem to figure this out, something that seems simple.

like image 835
jalapic Avatar asked Oct 29 '14 16:10

jalapic


2 Answers

More recent releases of shiny throw the following error if one uses a format argument:

The format argument to sliderInput is deprecated. Use sep, pre, and post instead. (Last used in version 0.10.2.2)

Now the preferred argument is evidently sep = ""

like image 164
duhaime Avatar answered Sep 30 '22 07:09

duhaime


NOTE: This answer was written for older versions of shiny. If you are using version 0.11 or higher consult @duhaime 's answer instead.

In the sliderInput add a format="####" argument. That will remove the comma.

While it would not make sense for years, you can also use the format argument to do things like control how decimals are displayed.# indicates a number should be shown when present and 0 indicates a number should be shown if present and a 0 will be shown if it is absent.

For example "####.00" will show number with two decimal places, no comma, but will not show the thousands place if it is not there. With this format the number 32.6 would appear as 32.60.

like image 37
John Paul Avatar answered Sep 30 '22 06:09

John Paul