rstudio / websocket

WebSocket client for R
https://rstudio.github.io/websocket/
Other
92 stars 18 forks source link

This Websocket Client Code, works well with Rstudio UI, but NOT working with R command-line interface #101

Closed skannan007 closed 1 year ago

skannan007 commented 1 year ago

When running from Rstudio UI: After ws <- WebSocket$new line execution, R listens for ws$onOpen ws$onMessage events. And in parallel runs rest of the code outside ws$onOpen ws$onMessage etc, till the end.

When running from unix shell script: Using below R commands [ Rscript /path/to/myRprogram .R (OR) R -f /path/to/myRprogram .R] After ws <- WebSocket$new line execution, R does NOT listen for ws$onOpen ws$onMessage events. It just runs rest of the code outside the functions ws$onOpen ws$onMessage etc, till the end and completely stops the program execution.

skannan007 commented 1 year ago

I found this solution from old posts, just added below code at the end of your websocket r program, after this I can run from command-line interface or shell script. while (TRUE) { if (ws$readyState() %in% c(2,3)) { break } else {later::run_now(1L)} }