autonumericInput {shinyWidgets}R Documentation

Autonumeric Input Widget

Description

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

Usage

autonumericInput(
  inputId,
  label,
  value,
  width = NULL,
  align = "right",
  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",
  style = 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 ”.

style

CSS styles (as a character string) to add to the ⁠<input>⁠ tag.

...

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

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)
}

[Package shinyWidgets version 0.8.6 Index]