[R] Help with Using gtext in gWidgetsWWW for Outputting Results to Webpage

jverzani jverzani at gmail.com
Sat May 7 18:28:10 CEST 2011


Ron Fricker <rdfricker <at> nps.edu> writes:

Ron,

A few things. 

I am in the process of rewriting this package to use the new Rook package. 
The current  package is on r-forge as gWidgetsWWW2. It works for local use, 
but Rook  isn't yet integrated in with rapache to serve in a public way. 
(https://r-forge.r-project.org/R/?group_id=761)

Second, the gtext widget has two methods for setting the text: svalue<- will 
replace the current text, and sounds like what you want. The insert method 
can  be used to add to the current text, either at the beginning or 
end (It just calls svalue in the end). It sounds like you are using insert.

Third, I had some issue with "\n" in the text, so added a call to some 
internal  method stripSlashN to replace \n with <br>. That might not be 
working for you. You can try to replace these yourself. The fact that 
gWidgetsWWW uses  proto (gWidgetsWWW2 doesn't) means you can 
hack some things. Here you  can bypass the stripSlashN call by 
redefining the method, doing something like:

t <- gtext("", ....) ## your usual call
t$setValueJS <- function(.,...) {
  out <- sprintf("%s.setValue('%s');", .$asCharacter(), .$..data)
  return(out)
}

You might need some other function wrapping .$..data, which stores the 
raw data. (The \n caused problems when passed back to the browser. 
The gWidgetsWWW2 implementation bypasses this, so should work better 
going  forward.)

Finally, the font stuff isn't implemented. I think (but didn't check) you can 
use HTML markup within your text.


Feel free to email directly if you want to.

--John

.. snip ...



More information about the R-help mailing list