-
Notifications
You must be signed in to change notification settings - Fork 157
/
Copy pathcurrencyInput.R
89 lines (69 loc) · 2.13 KB
/
currencyInput.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
#### Default ----
if (interactive()) {
library(shiny)
library(shinyWidgets)
ui <- fluidPage(
tags$h2("Currency Input"),
currencyInput("id1", "Euro:", value = 1234, format = "euro", width = 200, align = "right"),
verbatimTextOutput("res1"),
currencyInput("id2", "Dollar:", value = 1234, format = "dollar", width = 200, align = "right"),
verbatimTextOutput("res2"),
currencyInput("id3", "Yen:", value = 1234, format = "Japanese", width = 200, align = "right"),
verbatimTextOutput("res3"),
br(),
tags$h2("Formatted Numeric Input"),
formatNumericInput("id4", "Numeric:", value = 1234, width = 200),
verbatimTextOutput("res4"),
formatNumericInput("id5", "Percent:", value = 1234, width = 200, format = "percentageEU2dec"),
verbatimTextOutput("res5")
)
server <- function(input, output, session) {
output$res1 <- renderPrint(input$id1)
output$res2 <- renderPrint(input$id2)
output$res3 <- renderPrint(input$id3)
output$res4 <- renderPrint(input$id4)
output$res5 <- renderPrint(input$id5)
}
shinyApp(ui, server)
}
#### With Update Button
if (interactive()) {
library(shiny)
library(shinyWidgets)
ui <- fluidPage(
tags$h2("Currency Input"),
currencyInput("id1", "Euro:", value = 1234, format = "euro", width = 200, align = "right"),
verbatimTextOutput("res1"),
actionButton("bttn0", "Change Input to Euros"),
actionButton("bttn1", "Change Input to Dollars"),
actionButton("bttn2", "Change Input to Yen")
)
server <- function(input, output, session) {
output$res1 <- renderPrint(input$id1)
observeEvent(input$bttn0, {
updateCurrencyInput(
session = session,
inputId = "id1",
label = "Euro:",
format = "euro"
)
})
observeEvent(input$bttn1, {
updateCurrencyInput(
session = session,
inputId = "id1",
label = "Dollar:",
format = "dollar"
)
})
observeEvent(input$bttn2, {
updateCurrencyInput(
session = session,
inputId = "id1",
label = "Yen:",
format = "Japanese"
)
})
}
shinyApp(ui, server)
}