1

My problem is very basic (I am a beginner user in R). I am trying to collect the value selected from a gradio widget (gwidgets2 package for R).

I am using a similar script as this simplified one :

U=vector(mode="character")

DF=function() {
Win=gbasicdialog(handler=function(h,...) {
T=svalue(A)
print(T)
# I can print but not assign the value using : assign (U,T, .GlobalEnv)
})
A<-gradio(c("1","2","3"), selected=1,container=Win,)
out <- visible(Win)
}

DF()

Using this script, I am able to print the value selected in the gradio widget, but when I try to assign this value to another variable passed to the global environment, I get an error.

It is strange as this structure of script works fine to collect values from other widgets (like gtable). What am I doing wrong ?

Thanks for the help.

  • I'm guessing U is a zero length object. try "U". The suggestion in the answer also works, as would <<- – jverzani Jun 19 '16 at 17:52

1 Answers1

0

I am not sure what goes wrong, but was able to run your code with a small change:

DF <- function() {
  Win <- gbasicdialog(
    handler = function(h, ...) {
      .GlobalEnv$varT = svalue(A)
      print(varT)
    }
  )
  A   <- gradio(c("1", "2", "3"), selected = 1, container = Win)
  out <- visible(Win)
}

DF()

A small advice: avoid using the single letters T or F, as in your code T might be interpreted as TRUE and not object T.