R selects a line of a data frame interactively

I have a data frame, say:

df <- data.frame(a=1:10,b=runif(10)) 

I would like to be able to display the data frame for the user and select from them (click) a row, and get this row .

Something a bit like edit(df) , except that I want it a lot easier because I don't need editing functions. I just need to listen for the click event on one of the rows and get the index for that row (I don’t even need a specific cell!)

Does anyone know how I can do this? I would prefer to do this with an R or grid base (in order not to add a lot of packages) - maybe I can somehow draw a data frame on the grid graph with a scale defined from 1 to nrow(df) and use the grid.locator() function grid.locator() ?

It would be nice to avoid adding gui packages, but if I do, it should be cross-platform (linux / windows). gwidgets pretty nice (although they don't seem to have a click event that integrates perfectly with their gdf widget).

greetings.

+4
r interactive dataframe
Feb 07 2018-12-12T00:
source share
2 answers

Well, here's a quick way, no extra packages, but you might have to bother with formatting if you want the table to be well-aligned, rounded, etc.:

  df <- data.frame(a=1:10,b=runif(10)) df[menu(apply(df,1,paste,collapse=" "),graphics=TRUE),] 

If necessary, the device expands, and if necessary, scroll bars automatically appear.

+7
Feb 07 2018-12-12T00:
source share

I was going to suggest a combination of an empty portion filled with addtable2plot , and then use a locator to select a point and calculate a row with a combination of y specification and cellheight <- max(strheight(c(column.names, row.names, as.vector(unlist(table))) , ... but the efforts in this direction seem stupid, as @timrifle seems to hit a nail on the head.

0
Feb. 07 2018-12-12T00:
source share



All Articles