vendredi 9 février 2018

using lookup tables to plot a ggplot and table

I'm creating a shiny app and i'm letting the user choose what data that should be displayed in a plot and a table. This choice is done through 3 different input variables that contain 14, 4 and two choices respectivly. This adds up to 73 choices (yes, i know the math doesn't add up there, but some choices are invalid). I would like to do this using a lookup table so a created one with every valid combination of choices like this:

rad1<-c(rep("A",20), rep("B",20), rep("C", 13), rep("D", 20))

#choicesVariable contains the choices in the given input variable
rad2<-choicesVariable[c(1:14, 1,4,5,9,10,11, 1:14,1,4,5,9,10,11,1:7,9:14, 
1:14,1,4,5,9,10,11)]

rad3<-c(rep("A",14),rep("B",6), rep("A",14), rep("B",6), rep("A",27), 
rep("B",6))

letaLista<-data.frame(rad1,rad2,rad3)

Now its easy to use subset to only get the choice that the user made. But how do i use this information to plot the plot and table without using a 73 line long ifelse statment?

I tried to create some sort of multidimensional array that could hold all the tables (and one for the plots) but i couldn't make it work. My experience with these kind of arrays is limited and this might be a simple issue, but any hints would be helpful!

Aucun commentaire:

Enregistrer un commentaire