Search code examples
rgwidgets

embed function in gWidgets


Is there a way to embed the function edit(dataframe) in gwindow? example:

DataFrame <- data.frame(cbind(1,1:10)
edit(DataFrame)
Window <- gwindow()

I would like to embed edit(DataFrame) in Window.

Apostolos


Solution

  • The standard way to do this would be through a button click.

    dfr <- data.frame(x = 1:10, y = runif(10))
    win <- gwindow()
    btnEdit <- gbutton(
      "Edit", 
      container = win,
      handler = function(h, ...) dfr <<- edit(dfr)
    )
    

    You can be even fancier and decide whether or not the data frame should be editable or just viewable.

    win <- gwindow()
    btnEdit <- gbutton(
      "Edit", 
      container = win,
      handler = function(h, ...) 
      {
        if(svalue(chkReadonly)) View(dfr) else dfr <<- edit(dfr)
      }
    )
    chkReadonly <- gcheckbox(
      "Read-only", 
      FALSE,
      container = win,
      handler = function(h, ...) 
      {
        svalue(btnEdit) <- if(svalue(h$obj)) "View" else "Edit"
      }
    )
    

    Based upon your comment, what you want is even easier. Store the data frame in a gdf.

    tbl <- gdf(dfr, container = win)