Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Drop down list implementation in R

I am using the following code for the Share Price Application I have been developing (with plenty of help from people here that is greatly appreciated!). One of the things it should do is allow the user to pick a company to analyse from stored XML Files, I have been using the following code to do this:

df <- xmlToDataFrame(file.choose())

Instead of using file.choose () {as apparently the dialogue box reveals to much of the system structure}, it has been suggested to use a drop down menu, with a list of the companies and a link to the file.

Is such a thing possible in R and is there an easy-ish way of implementating it?

like image 734
Anthony Keane Avatar asked Aug 26 '10 10:08

Anthony Keane


2 Answers

select.list allow you to select from a list. Check also menu.

Examples:

Using menu

companies <- c("AAA","BBB","CCC")
links <- c("c:/file1","c:/secret/file3","c:/file3")

i <- menu(companies, graphics=TRUE, title="Choose company")
df <- xmlToDataFrame(links[i])

Using select.list

companies <- c("AAA","BBB","CCC")
links <- c("c:/file1","c:/secret/file3","c:/file3")

i <- select.list(companies, title="Choose company")
df <- xmlToDataFrame(links[companies==i])

If you want to show name and link on list then use

menu_items <- paste(companies, " (", links, ")", sep="")
i <- select.list(menu_items, title="Choose company")
df <- xmlToDataFrame(links[menu_items==i])
like image 70
Marek Avatar answered Sep 30 '22 23:09

Marek


If you don't want to get into tcltk programming, try the gWidgets packages.

library(gWidgetstcltk) # or library(gWidgetsRGtk2), etc.
drp <- gdroplist(c("AAA", "BBB", "CCC"), container = gwindow())
like image 32
Richie Cotton Avatar answered Sep 30 '22 23:09

Richie Cotton