Last active
January 6, 2020 13:09
-
-
Save gsee/4384158 to your computer and use it in GitHub Desktop.
simple streaming shiny plot
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
set.seed(42) | |
dat <- rnorm(1) | |
shinyServer(function(input, output) { | |
fetchData <- reactive(function() { | |
invalidateLater(1000) | |
qt <- rnorm(1) | |
dat <<- c(dat, qt) | |
dat | |
}) | |
output$plot_dat <- reactivePlot(function() { plot(fetchData(), type='l') }) | |
# Allow user to download data from server | |
output$downloadData <- downloadHandler( | |
filename = function() { "streaming.csv" }, | |
content = function(file) { | |
write.csv(dat, file) | |
} | |
) | |
}) |
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
shinyUI(bootstrapPage( | |
div(class="container", | |
plotOutput("plot_dat"), | |
downloadButton('downloadData', 'Download') | |
) | |
)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment