-
Notifications
You must be signed in to change notification settings - Fork 157
/
Copy pathautonumericInput.R
127 lines (115 loc) · 2.99 KB
/
autonumericInput.R
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#### Regular 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 = " €",
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)
}
#### Examples with Update Buttons ----
if (interactive()) {
library(shiny)
library(shinyWidgets)
ui <- fluidPage(
h1("AutonumericInput Update Example"),
br(),
autonumericInput(
inputId = "id1",
label = "Autonumeric Input",
value = 1234.56,
align = "center",
currencySymbol = "$ ",
currencySymbolPlacement = "p",
decimalCharacter = ".",
digitGroupSeparator = ","
),
verbatimTextOutput("res1"),
actionButton("bttn1", "Change Input to Euros"),
actionButton("bttn2", "Change Input to Dollars"),
br(),
br(),
sliderInput("decimals", "Select Number of Decimal Places", value = 2, step = 1, min = 0, max = 6),
actionButton("bttn3", "Update Number of Decimal Places")
)
server <- function(input, output, session) {
output$res1 <- renderPrint(input$id1)
observeEvent(input$bttn1, {
updateAutonumericInput(
session = session,
inputId = "id1",
label = "Euros:",
value = 6543.21,
options = list(
currencySymbol = "€",
currencySymbolPlacement = "s",
decimalCharacter = ",",
digitGroupSeparator = "."
)
)
})
observeEvent(input$bttn2, {
updateAutonumericInput(
session = session,
inputId = "id1",
label = "Dollars:",
value = 6543.21,
options = list(
currencySymbol = "$",
currencySymbolPlacement = "p",
decimalCharacter = ".",
digitGroupSeparator = ","
)
)
})
observeEvent(input$bttn3, {
updateAutonumericInput(
session = session,
inputId = "id1",
options = list(
decimalPlaces = input$decimals
)
)
})
}
shinyApp(ui, server)
}