How can I change the number format of widgets in Shiny?
I have a slider going from 0 to 1 but I'd prefer having it going from 0% to 100%. I know I could just multiply the numbers by 100 but then I would still not be able to display numbers in percent. Is it possible to do so?
EDIT
Since this was marked as a duplicate: the other post proposed that one uses format =
but R tells me that piece of codes is depreciated.
On the Home tab, in the Number group, click the icon next to Number to display the Format Cells dialog box. In the Format Cells dialog box, in the Category list, click Percentage. In the Decimal places box, enter the number of decimal places that you want to display.
To convert a decimal to a percentage, multiply by 100 (just move the decimal point 2 places to the right). For example, 0.065 = 6.5% and 3.75 = 375%. To find a percentage of a number, say 30% of 40, just multiply. For example, (30/100)(40) = 0.3 x 40 = 12.
To show a number as a percent in Excel, you need to apply the Percentage format to the cells. Simply select the cells to format, and then click the Percent Style (%) button in the Number group on the ribbon's Home tab. You can then increase (or decrease) the the decimical place as needed.
If you want to add percentage sign to a number without multiplying the number by 100, such as to change 6 into 6% in Excel with Percentage Style, you should have the general number divided by 100 first, and then apply the Percentage Style to the numbers for displaying them as percentage 6% in Excel.
You can use the post
argument to sliderInput
.
http://shiny.rstudio.com/reference/shiny/latest/sliderInput.html
library(shiny)
ui <- shinyUI(
fluidPage(
sliderInput("mySlider",label="my slider", min = 0, max = 100, post = " %", value = 50)
)
)
server <- shinyServer(function(input, output) {
})
shinyApp(ui=ui, server=server)
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