Help with Using gtext in gWidgetsWWW for Outputting Results to Webpage

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Help with Using gtext in gWidgetsWWW for Outputting Results to Webpage

Ron Fricker
All:  Using gWidgetsWWW, I'm in the process of designing a website that will provide users with a GUI to interact with various datasets.  As part of that, I want to provide users the ability select particular variables (via combo boxes) that will then result in summary (text) output being returned to the webpage.  Think of it as their choices ultimately result in a one- or two-way table being returned from the R table() function.

The way I have implemented it is with a series of comboboxes that users use to make selections and that ultimately return table() output to a gtext widget.  In so doing, I was essentially following the example at the end of "Examples for gWidgets" (Section 17.2, An alternative to ggenericwidget).  Right now I'm testing the code on my local PC using localServerOpen().  

The problem is not with the function, but with the output.  Specifically, in the output the formatting (particularly newline returns) are stripped out and my table turns into a long string of numbers.  Similarly, any text that I add to the gtext widget is just appended.  So, I just get a long string of text and numbers that is essentially unintelligible.

What I want is output similar to what I would see in the R Console were I to generate a table there.  In an attempt to correct this, I have tried all manner of font options such as font.attr=c("monospace"), etc., and it seems that no matter what I try I can neither affect the displayed font (it's some sort of proportional Arial-like font) nor the exclusion of line returns.  (When I include \n in the text, it's simply stripped out/ignored.  However, \t works.)

Now, when I run the same code under gWidgets, I get a Courier-style font and the line returns show up.  That is, the output in the gtext widget looks much like I would see in the R Console.  So, my guess is that the browser is overriding the gWidgetsWWW output.  I'm running this in the latest version of Firefox.  (When I ran the same code using IE 9.0, the gtext widget does not even show up, but that's a different issue...)

With all that as background, two questions:

(1) Is the use of the gtext widget a good approach for what I want to do, or is there a better approach?

(2) If the gtext widget is the way to go, any suggestions for solving the above problem?

Many thanks,
Ron
Associate Professor
Operations Research Dept.
Naval Postgraduate School
Monterey, CA, USA
Reply | Threaded
Open this post in threaded view
|

Re: Help with Using gtext in gWidgetsWWW for Outputting Results to Webpage

jverzaniNWBKZ
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 ...

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: Help with Using gtext in gWidgetsWWW for Outputting Results to Webpage

jverzaniNWBKZ
jverzani <jverzani <at> gmail.com> writes:


I was remiss in not mentioning the use of the nifty hwriter package for
formatting  tables for display through ghtml as an alternative to using
gtext for what you want  to do. See the package description at:
http://www.embl.de/~gpau/hwriter/

--John

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.