knitr::opts_chunk$set(echo = TRUE)
# library(magrittr) library(realtime) ## plot with a theme_grey() feel ## also has a floating rectangle to ## demonstrate that the sketch is ## chained correctly realtime(w = 600, h = 500) %>% theme_grey() %>% fill("#000000") %>% rect(100, 100, 100, 100) ## a theme_bw option realtime(w = 600, h = 500) %>% theme_bw() %>% fill("#000000") %>% rect(100, 120, 100, 100) ## link to a stream coming from a websocket realtime(w = 600, h = 500) %>% theme_grey() %>% add_data_stream('ws://localhost:9454/') ## this would be neater if it was the *first* part of the chain ## for example, create a websocket of random data library(httpuv) library(jsonlite) app <- list( call = function(req) { stop("call is not implemented. Something is wrong if you see this") }, onWSOpen = function(ws) { id = 1 while(TRUE){ x = rnorm(1, 150, 50) print(x) ws$send(toJSON(list(x = x))) Sys.sleep(0.02) id = id+1 } } ) ## and run the server runServer("0.0.0.0", 9454, app, 250) library(httpuv) library(jsonlite) #library(devtools) #install("/Users/yan/Desktop/REALTIME/realtime") library(realtime) library(Rbitcoin) # github realtime(w = 600, h = 500) %>% theme_grey() %>% add_data_stream('ws://localhost:9454/') options(Rbitcoin.antiddos.sec = 0.1) app <- list( call = function(req) { stop("call is not implemented. Something is wrong if you see this") }, onWSOpen = function(ws) { id = 1 while(TRUE){ x = (as.numeric(fromBTC(1, antiddos = 0.1))-7250) + runif(1, -10, 10) #x=3 print(x) ws$send(toJSON(list(x = x))) Sys.sleep(0.1) id = id+1 } } ) #liveplot() runServer("0.0.0.0", 9454, app, 250) ### library(realtime) library(httpuv) library(jsonlite) realtime(w = 600, h = 500) %>% theme_grey() %>% add_data_stream('ws://localhost:9454/') # https://qrng.anu.edu.au/ran_hex.php app <- list( call = function(req) { stop("call is not implemented. Something is wrong if you see this") }, onWSOpen = function(ws) { id = 1 while(TRUE){ x = strtoi(rvest::html_text(httr::content(httr::GET("https://qrng.anu.edu.au/ran_bin.php"))), 2L) #x=3 print(x) ws$send(toJSON(list(x = x))) Sys.sleep(0.01) id = id+1 } } ) #liveplot() runServer("0.0.0.0", 9454, app, 250)
TODO:
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.