1

I have a SpatialLinesDataFrame named df with a number of attributes. These attributes represent the permutations of three dimensions:

  • dim1
  • dim2
  • dim3

The attributes thus are:

  • df$dim1a.dim2a.dim3a
  • df$dim1a.dim2a.dim3b
  • df$dim1a.dim2b.dim3a
  • ...
  • df$dim1b.dim2a.dim3a
  • df$dim1b.dim2a.dim3b
  • ...
  • df$dim1n.dim2n.dim3n

I am now trying to make my data accessible in Shiny, where I offer a widget item for each dimensions that allows the user select one value for that dimension. If the user selects

  • dim1a
  • dim2c
  • dim3b

I want to display data for df$dim1a.dim2c.dim3b.

How can I dynamically access the part of the data frame that the user is asking to have displayed?

I can construct the name of the attribute by constructing it via

display_data <- paste0(input$radioButton_dim1,'.',input$radioButton_dim2,'.',input$radioButton_dim3)

But how can I refer to it when trying to select it from the df or subset the data frame to select the data?

+++ Update:

When I try subsetting the data frame by using df[,display_data], the objects of class "Lines" are being returned. If I just use df$dim1a.dim2c.dim3b, I get a list of the actual attribute values for those objects, which is what I am looking for.

+++

If this is not easily feasible or not recommended for some reason, can something like melting/casting also be performed on a SpatialLinesDataFrame?

matt_jay
  • 1,241
  • 1
  • 15
  • 33
  • 1
    Possible duplicate of [R how use a string variable to select a data frame column using $ notation](http://stackoverflow.com/questions/23717397/r-how-use-a-string-variable-to-select-a-data-frame-column-using-notation) – CL. Feb 12 '16 at 18:39
  • Thanks @CL. for pointing this out. I had already played with the (single) bracket notation to no avail. I will gp through all suggestions made in the referenced post (and references therein) and update my question. – matt_jay Feb 12 '16 at 18:47
  • I don't now if there is something special about `SpatialLinesDataFrame` (as compared to a normal `data.frame`), but a simple `df[, display_data]` should give you the column indicated by the value of `display_data`. – CL. Feb 12 '16 at 18:49
  • 1
    SpatialLinesDataFrames are not really dataframes but rather S4 objects, needing different accessor functions. – IRTFM Feb 12 '16 at 21:24
  • I updated my OP. I do not get the same results from using bracket notation as when referring to the attribute wit df$... Any other ideas? – matt_jay Feb 13 '16 at 14:39
  • Could you add a reproducible example that generates a `SpatialLinesDataFrame` along with a possilbe selector? – CL. Feb 13 '16 at 14:46

0 Answers0