Reputation: 136
I am trying to make a shiny currency exchange app in R. This is what i have done so far:
ui.R
shinyUI(pageWithSidebar(
headerPanel("European Exchange Rates"),
sidebarPanel(
selectInput("variable", "Change:",
list("EUR" = "European Euro",
"ATS" = "Austrian Schilling",
"DEM" = "German Mark",
"ESP" = "Spanish Peseta",
"FIM" = "Finnish Markka",
"FRF" = "French Franc",
"IEP" = "Irish Pound",
"ITL" = "Italian Lira",
"LUF" = "Luxembourgian Franc",
"NLG" = "Dutch Guilder",
"PTE" = "Portuguese escudo",
"BEF" = "Belgian Franc",
"CYP" = "Cypriot Pound",
"EEK" = "Estonian Kroon",
"GRD" = "Greek Drachma",
"SIT" = "Slovenian Tolar")),
selectInput("variable2", "To:",
list("EUR" = "European Euro",
"ATS" = "Austrian Schilling",
"DEM" = "German Mark",
"ESP" = "Spanish Peseta",
"FIM" = "Finnish Markka",
"FRF" = "French Franc",
"IEP" = "Irish Pound",
"ITL" = "Italian Lira",
"LUF" = "Luxembourgian Franc",
"NLG" = "Dutch Guilder",
"PTE" = "Portuguese escudo",
"BEF" = "Belgian Franc",
"CYP" = "Cypriot Pound",
"EEK" = "Estonian Kroon",
"GRD" = "Greek Drachma",
"SIT" = "Slovenian Tolar"))
),
mainPanel(
h3('Exchanged Currency'),
h4("From"),
verbatimTextOutput("oid1"),
h4("To"),
verbatimTextOutput("oid2"),
h4("Amount"),
verbatimTextOutput("amount")
)
))
server.R
shinyServer(
function(input, output) {
output$oid1 <- renderPrint({input$variable})
output$oid2 <- renderPrint({input$variable2})
output$amount <- renderPrint({input$amount})
}
)
I assume I have to add the exchange rates in the ui.R
, with numericInput
but i just don't know how to set the combinations with the currencies. I have the rates taken from the R dataset euro.cross
. I would appreciate some indications on how to continue.
Upvotes: 2
Views: 1771
Reputation: 30425
You can adjust the euro.cross
data set slightly adding a EUR
row to it and a EUR
column:
Define some globals:
tempcross <- rbind.data.frame(euro, euro.cross)
tempcross$EUR <- c(1, 1/euro)
row.names(tempcross)[1] <- "EUR"
currencies <- list("EUR" = "European Euro",
"ATS" = "Austrian Schilling",
"DEM" = "German Mark",
"ESP" = "Spanish Peseta",
"FIM" = "Finnish Markka",
"FRF" = "French Franc",
"IEP" = "Irish Pound",
"ITL" = "Italian Lira",
"LUF" = "Luxembourgian Franc",
"NLG" = "Dutch Guilder",
"PTE" = "Portuguese escudo",
"BEF" = "Belgian Franc",
"CYP" = "Cypriot Pound",
"EEK" = "Estonian Kroon",
"GRD" = "Greek Drachma",
"SIT" = "Slovenian Tolar")
run the app
runApp(
list(ui = pageWithSidebar(
headerPanel("European Exchange Rates"),
sidebarPanel(
selectInput("variable", "Change:", currencies),
selectInput("variable2", "To:", currencies)
),
mainPanel(
h3('Exchanged Currency'),
h4("From"),
verbatimTextOutput("oid1"),
h4("To"),
verbatimTextOutput("oid2"),
h4("Amount"),
verbatimTextOutput("amount")
)
)
, server = function(input, output) {
output$oid1 <- renderPrint({input$variable})
output$oid2 <- renderPrint({input$variable2})
output$amount <- renderPrint({
curr1 <- names(currencies[currencies %in% input$variable])
curr2 <- names(currencies[currencies %in% input$variable2])
tempcross[curr1, curr2]
})
}
)
)
Upvotes: 2