autonumericInput: Autonumeric Input Widget

Description Usage Arguments Details Value References See Also Examples

View source: R/input-autonumeric.R

Description

An R wrapper over the javascript AutoNumeric library, for formatting numeric inputs in shiny applications.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
autonumericInput(
  inputId,
  label,
  value,
  width = NULL,
  align = "center",
  currencySymbol = NULL,
  currencySymbolPlacement = NULL,
  decimalCharacter = NULL,
  digitGroupSeparator = NULL,
  allowDecimalPadding = NULL,
  decimalPlaces = NULL,
  divisorWhenUnfocused = NULL,
  rawValueDivisor = NULL,
  formatOnPageLoad = NULL,
  maximumValue = NULL,
  minimumValue = NULL,
  modifyValueOnWheel = NULL,
  emptyInputBehavior = "null",
  ...
)

Arguments

inputId

The input slot that will be used to access the value.

label

Display label for the control, or NULL for no label.

value

Initial value (unformatted).

width

The width of the input box, eg. "200px" or "100%".

align

The alignment of the text inside the input box, one of "center" (default), "left", "right".

currencySymbol

Defines the currency symbol string. It can be a string of more than one character (allowing for instance to use a space on either side of it, example: '$ ' or ' $'). Defaults to "".

currencySymbolPlacement

Defines where the currency symbol should be placed, "p" for prefix or "s" for suffix (default).

decimalCharacter

Defines what decimal separator character is used. Defaults to ",".

digitGroupSeparator

Defines what decimal separator character is used. Defaults to ".".

allowDecimalPadding

Defines if decimal places should be padded with zeros. Defaults to TRUE.

decimalPlaces

Defines the default number of decimal places to show on the formatted value, and keep for the precision. Must be 0 or a positive integer. Defaults to 2.

divisorWhenUnfocused

The number that divides the element value on blur. On focus, the number is multiplied back in. Defaults to NULL.

rawValueDivisor

Divides the formatted value shown in the AutoNumeric element and store the divided result in rawValue. Defaults to 1.

formatOnPageLoad

Determine if the default value will be formatted on initialization. Defaults to TRUE.

maximumValue

Defines the maximum possible value a user can enter.

minimumValue

Defines the minimum possible value a user can enter.

modifyValueOnWheel

Allows the user to increment or decrement the element value with the mouse wheel. The wheel behavior can be modified by the wheelStep option. Defaults to TRUE.

emptyInputBehavior

Defines what should be displayed in the element if the raw value is an empty string ”.

...

Additional parameters that can be passed to AutoNumeric. See details for more information.

Details

This function wraps the AutoNumeric.js library. The parameter documentation provided here should be sufficient for most users, but for those wishing to use advanced configurations it is advised to look at the documentation on the AutoNumeric GitHub repository. Alexandre Bonneau has done a wonderful job of documenting all parameters and full explanations of all parameters and their associated values can be found there.

The ... parameter can take any of the arguments listed on the AutoNumeric GitHub repository. A quick reference follows:

Value

An autonumericInput object to be used in the UI function of a Shiny App.

References

Bonneau, Alexandre. 2018. "AutoNumeric.js javascript Package". http://autonumeric.org

See Also

Other autonumeric: currencyInput(), updateAutonumericInput(), updateCurrencyInput()

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
if (interactive()) {
  library(shiny)
  library(shinyWidgets)

  ui <- fluidPage(
    h1("Autonumeric Inputs"),
    br(),
    autonumericInput(
      inputId = "id1",
      label = "Default Input",
      value = 1234.56
    ),
    verbatimTextOutput("res1"),

    autonumericInput(
      inputId = "id2",
      label = "Custom Thousands of Dollars Input",
      value = 1234.56,
      align = "right",
      currencySymbol = "$",
      currencySymbolPlacement = "p",
      decimalCharacter = ".",
      digitGroupSeparator = ",",
      divisorWhenUnfocused = 1000,
      symbolWhenUnfocused = "K"
    ),
    verbatimTextOutput("res2"),

    autonumericInput(
      inputId = "id3",
      label = "Custom Millions of Euros Input with Positive Sign",
      value = 12345678910,
      align = "right",
      currencySymbol = "\u20ac",
      currencySymbolPlacement = "s",
      decimalCharacter = ",",
      digitGroupSeparator = ".",
      divisorWhenUnfocused = 1000000,
      symbolWhenUnfocused = " (millions)",
      showPositiveSign = TRUE
    ),
    verbatimTextOutput("res3")
  )

  server <- function(input, output, session) {
    output$res1 <- renderPrint(input$id1)
    output$res2 <- renderPrint(input$id2)
    output$res3 <- renderPrint(input$id3)
  }

  shinyApp(ui, server)
}

Example output



shinyWidgets documentation built on Sept. 17, 2021, 5:06 p.m.