Skip to content

Instantly share code, notes, and snippets.

@gsee
Last active January 6, 2020 13:09
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save gsee/4384158 to your computer and use it in GitHub Desktop.
Save gsee/4384158 to your computer and use it in GitHub Desktop.
simple streaming shiny plot
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)
}
)
})
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