I'm trying to create a GUI in R where the user can add, edit, or search entries within a data frame. For adding a new entry I created the "Add" button which opens a new window. The code is as follows:
Add <- gbutton("Add Entry",
handler = function(h,...){
Input <- gwindow("Input New Entry")
Vals <- ggroup(horizontal = F, use.scrollwindow = T, container = Input)
COLS <- 1:length(colnames(Data))
Text <- vector()
for (n in COLS) {
ADDS <- gedit(initial.msg = colnames(Data)[n], container = Vals)
Text[n] <- ADDS[]
}
SAVE <- gbutton("Add Entry",horizontal = F,
handler = function(h,...){
Tab[DIM[1]+1,] <- Text
DIM[1] = DIM[1] + 1
dispose(Input)
},
container = Vals)
},
container = Bttns)
For reference Data
is the original data frame used, DIM
is the vector with the dimensions of the data frame, Bttns
is the group in which the Add
button appears in the original window, and Tab
is the data frame table added in the original window with gdf
.
My goal is to create a gedit
for each column entry in Data
and to then append the new entry as the last row in the original data frame. Creating each gedit
manually seems to defeat the purpose of computer programming. Is there a way I can save a vector of widgets? The preceding code doesn't give any errors, but it doesn't save the data after it is entered into the new window. Is there an easier way to do this other than using a for loop? Any help is appreciated!