Skip to content

Instantly share code, notes, and snippets.

@gsee

gsee/server.R

Last active Oct 13, 2015
Embed
What would you like to do?
shiny TrueFX quotes
# Based on (more) code by Joe Cheng:
# https://groups.google.com/d/msg/shiny-discuss/NE-LqDAVqQQ/kNdrtC4WxGAJ
# https://gist.github.com/4044364
#-------------------------------------------------------------------------------
if (!require(TFX) && !require(TrueFX)) {
stop("TFX must be installed; run 'install.packages(\"TFX\")'.\n")
}
shinyServer(function(input, output, session) {
output$currentTime <- renderText({
# Forces invalidation in 1000 milliseconds
invalidateLater(1000, session)
as.character(Sys.time())
})
fetchData <- reactive({
if (!input$pause)
invalidateLater(750)
qtf <- QueryTrueFX()
qtf$TimeStamp <- as.character(qtf$TimeStamp)
names(qtf)[6] <- "TimeStamp (GMT)"
qtf[, c(6, 1:3, 5:4)]
})
output$fxdata <- renderTable({
fetchData()
}, digits=5, row.names=FALSE)
})
Sys.setenv(TZ="America/New_York")
zones <- attr(as.POSIXlt(Sys.time()), "tzone")
zone <- if (zones[[1]] == "") {
paste(zones[-1], collapse="/")
} else zones[[1]]
shinyUI(bootstrapPage(
div(class="container",
p(strong(paste0("Current time (", zone, "):")),
textOutput("currentTime")
),
p(strong("Latest FX Quotes:"),
tableOutput("fxdata"),
checkboxInput("pause", "Pause updates", FALSE))
)
))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment