I am looking to create GUI that takes in a few inputs from the user (for example gender, age, and race as clickable categories), then assigns a user ID to each input (which would be displayed as the output in the GUI). Under the hood would be a dataset that the GUI is creating with this user input (In this example, it would be 4 variables: user ID, gender, age, and race).
Has anyone created a GUI like this before? Any R package or code recommendations?
Thanks!
We have developed a software tool called R GUI Generator (RGG) which enables the easy generation of Graphical User Interfaces (GUIs) for the programming language R by adding a few Extensible Markup Language (XML) – tags. RGG consists of an XML-based GUI definition language and a Java-based GUI engine.
Open a new project in RStudio. Go to the 'File' menu and click on 'New Project. ' Then select 'New Directory,' and 'R Package' to create a new R package.
Under the hood would be a dataset that the GUI is creating with this user input (In this example, it would be 4 variables: user ID, gender, age, and race). Has anyone created a GUI like this before? Any R package or code recommendations?
devtools - An essential suite of tools for turning your code into an R package. testthat - testthat provides an easy way to write unit tests for your code projects. roxygen2 - A quick way to document your R packages. roxygen2 turns inline code comments into documentation pages and builds a package namespace.
If you are going to create code and put it into production, it’s always a good idea to create a package with version control, examples, and other features. Plus, with RStudio, it is easy to do. So, we will use a simple example with one small function to show how easy it is.
For R and package development in particular, your IDE is RStudio. Use it. The R package that will help you develop R Packages is devtools. Install this package and use it as outlined in Wickham’s R Packages. But you already know this because you already read R Packages like I suggested! Lastly, you must use version control.
There are lots of ways to do this. Here is one using the add-on package gWidgets. Should work with either RGtk2 or tcltk backends.
library(gWidgets)
items <- data.frame(id=numeric(0), gender=character(0), age=numeric(0), race=character(0), stringsAsFactors=FALSE)
genders <- c("Male", "Female")
race <- c("Black", "Hispanic", "Other")
w <- gwindow("Capn's GUI", visible=FALSE)
g <- ggroup(cont=w, horizontal=FALSE)
lyt <- glayout(cont=g)
lyt[1,1] <- "Gender:"
lyt[1,2] <- gradio(genders, cont=lyt)
lyt[2,1] <- "Age:"
lyt[2,2] <- gedit("40", coerce.with=as.numeric, cont=lyt)
lyt[3,1] <- "Race:"
lyt[3,2] <- gcombobox(race, selected=0L, cont=lyt)
lyt[4,2] <- gbutton("Add", cont=lyt, handler=function(h,...) {
vals <- lapply(lyt[1:3, 2], svalue)
id <- nrow(items) + 1 # or roll your own
items[id, ] <<- c(id, vals)
tbl[] <- items
})
gseparator(cont=g)
tbl <- gtable(items, cont=g)
visible(w) <- TRUE
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With