Use an R Session as a Websocket Server
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
This is VERY simple R function that when ran turns your R session into a websocket server. For this example it returns the standard deviation from a JSON encoded array sent via websockets.
This method can be used to do all sorts of things, include return information for the R workspace environment and even dynamically run code through the use of eval() on your global environment (not recommended for security reasons). If you want to respond with the workspace environment information simply swap out ws$send() with the following…
ws$send(toJSON(ls(envir = .GlobalEnv)))
Hope this is useful for someone. I will be putting together a much more involved tutorial sometime down the road that will cover dashboards outside the use of Shiny.
R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.