Question

I am trying to show the results summary using gWidgets, but I cannot find a widget that can do the job easily.

For example,

ctl <- c(4.17,5.58,5.18,6.11,4.50,4.61,5.17,4.53,5.33,5.14)
trt <- c(4.81,4.17,4.41,3.59,5.87,3.83,6.03,4.89,4.32,4.69)
group <- gl(2,10,20, labels=c("Ctl","Trt"))
weight <- c(ctl, trt)
lm.D9 <- lm(weight ~ group)

I would like to have a window or a text box which prints summary(lm.D9). like the following:

Call:
lm(formula = weight ~ group)

Residuals:
    Min      1Q  Median      3Q     Max 
-1.0710 -0.4938  0.0685  0.2462  1.3690 

Coefficients:
            Estimate Std. Error t value Pr(>|t|)    
(Intercept)   5.0320     0.2202  22.850 9.55e-15 ***
groupTrt     -0.3710     0.3114  -1.191    0.249    
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 

Residual standard error: 0.6964 on 18 degrees of freedom
Multiple R-squared: 0.07308,    Adjusted R-squared: 0.02158 
F-statistic: 1.419 on 1 and 18 DF,  p-value: 0.249

This can be easily done with shiny using renderPrint and verbatimTextOutput. I am hoping that there is also something in gWidgets.

A related question, I can use capture.output to write the summary into a text file. It would be helpful if there is a widget that can open the text file and show the content in the user interface.

Was it helpful?

Solution

Use gtext and capture.output:

out <- paste(capture.output(summary(lm.D9)), collapse="\n")
w <- gwindow()
txt <- gtext(out, cont=w, font.attr=c(family="monospace"))

OTHER TIPS

You can maybe use glabel for example:

win <- gwindow("Summary regression", visible=TRUE)
group <- ggroup(horizontal = FALSE, container=win)
obj <- glabel(as.character(summary(lm.D9)), 
         container=group, font.attr=list(style="bold"))

enter image description here

The result is not so beautiful, but I think it is a good start...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top