Use an R Session as a Websocket Server

April 23, 2017

(This article was first published on | R Language Programming, and kindly contributed to R-bloggers)

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.

To leave a comment for the author, please follow the link and comment on their blog: | R Language Programming. offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...

If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.

Search R-bloggers


Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)