我正试图在R中制作一个闪亮的货币兑换应用程序。这是我到目前为止所做的:
的 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})
}
)
我假设我必须使用ui.R
在numericInput
中添加汇率,但我只是不知道如何设置货币组合。我从R数据集euro.cross
获得了费率。我很感激有关如何继续的一些迹象。
答案 0 :(得分:2)
您可以调整euro.cross
数据集,稍微向其添加EUR
行和EUR
列:
定义一些全局变量:
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")
运行应用
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]
})
}
)
)