shiny's session$sendCustomMessage, and dean attali's shinyjs package both support R-to-browser API calls in shiny after the widget is created.
But after hours of web search and code examination, I have not been able to find that capability for non-shiny interactive htmlwidgets - that is, for widgets created and used from the plain old R console. Any tips? I'll be grateful.
This style of use would then become practical, sharing code & build process with the shiny usable version:
R> w <- myWidget("initialValue")
R> setNewValue(w, "fubar")
R> shouldBeFubar <- getValue(w)
(user changes value directly, typing into the browser)
R> print(getValue(w)) # we see "I typed this directly into the web browser"
(For what it's worth, I have used RStudio's httpuv to create my own implementation, a websocket message-passing from R console to browser and back. I hope to retire that bioconductor package, and depend instead on only htmlwidgets.
See BrowserViz and igvR for my implementation. Naturally I use htmlwidgets for igvShiny, working in a separate code base. I'd like to consolidate the code of these two very similar packages, and to have full R-to-browser API messaging in both shiny and console versions.)