Last active
October 13, 2015 02:08
-
-
Save gsee/4122626 to your computer and use it in GitHub Desktop.
shiny TrueFX quotes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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) | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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