Reputation: 53
I am new to R and I am creating a shiny application to read a csv and filter data. I am reading the csv file, then creating dropdowns with a loop using the column names and the unique values:
output$dropdowns <- renderUI({
if (is.null(x())) {
return(NULL)
}
lapply(1:ncol(x()), function(i) {
selectInput(names(x()[i]), names(x()[i]), c("ALL", unique(as.character(x()[,i]))))
})
I am now trying to filter the data based on the input from the user. To get the input I am trying to loop through the names (names(x)[i]
), which is the ID of the selectinput and get the value. But whenever I use input$names(x)[i]
, I get the following error:
Error: attempt to apply non-function.
I have tried to test this using an actual header (e.g. input$testHeader) and this works fine. But when I try to do the same with a variable, e.g.:
a < - "testHeader"
print(input$a).
This returns NULL. I assume it is looking for a selecinput with ID "a" and cannot find it. But I have no idead how else to try?
Any help would be great.
Thanks.
Upvotes: 2
Views: 8021
Reputation: 330453
input
is just a reactivevalues
object so you can use [[
:
print(input[[a]])
Upvotes: 5