Skip to content

Instantly share code, notes, and snippets.

@gsee
Last active October 13, 2015 02:08
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save gsee/4122626 to your computer and use it in GitHub Desktop.
Save gsee/4122626 to your computer and use it in GitHub Desktop.
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