I am building a shiny application which has a dynamic user interface, meaning when a user specifies that there are 7 "concentrations" I have made it so that the tabPanel will generate 7 numericInput fields for the user to enter each of the concentrations. This feature works really well, however, I am having an issue accessing the data from each of those fields. I will provide more detail below. But in summary, I have a vector of strings, each of which is the name of one of my input variables. Is there a way for me to iterate through this vector of strings, and turn each one into the value of its respective variable?
Example:
I have set my numericInput() to 7, and so the user interface will generate 7 new numericInput fields using a schemed labeling system that iterates. I have written a method which takes the number from the original and generates a vector of labels. I would like to be able to access the value within each of these variables.
Here is the code that generates my vector of strings:
generate_labels <- function(trunk,num) {
list <- vector("character", num)
for (i in seq_len(num)) {
list[i] <- (paste0("input$",trunk,"_", i))
}
list
}
So, a sample input could be:
c("input$var1", "input$var2", input$var3", input$var4", input$var5", input$var6", input$var7")
And they may correspond to
input$var1 = 1000
input$var2 = 500
input$var3 = 3
input$var4 = 400
input$var5 = 200
input$var6 = 1
input$var7 = 150
I would be able to ouput a vector that is:
c(1000, 500, 3, 400, 200, 1, 150)
Here is one of my stabs at it. I am assuming that I will require the function eval(), assign(), and or get().
a <- 1
b <- 2
c <- 3
sting_list <- c("a", "b", "c")
find_value <- function(in_frame) {
#we cant to return a new function
out_frame <- vector("numeric", length(in_frame))
for (i in 1:length(in_frame)) {
assign(out_frame[i], get(in_frame[i]))
}
out_frame
}
find_value(sting_list)
Please let me know if you have any suggestions, or if there is any problem with the problem I have provided. i would be happy to make the appropriate edits.
Thanks in advanced,
Chris