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 dateRangeInput
in 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.
More recent releases of shiny throw the following error if one uses a format
argument:
The
format
argument to sliderInput is deprecated. Usesep
,pre
, andpost
instead. (Last used in version 0.10.2.2)
Now the preferred argument is evidently sep = ""
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With