Reputation: 635
I am building a shiny app. I want to render the factors for every column chosen. To do this I have two selectInput widgets. While the first one renders the column names and the second one should render the factors of the column selected by the first widget. The code that I wrote is not rendering the factors, while the same is working outside shiny environment. The code is as follows:
1st selectInput:
observe({
updateSelectInput(session, "filt", choices = sort(as.character(colnames(s()))))
})
2nd selectInput - to return factors for column selected in 'filt' selectInput.
observe({
updateSelectInput(session, "filt1", choices = sort(as.character(unique(s()$input$filt))))
})
A reproducible table:
structure(list(Gender = structure(c(2L, 1L, 2L, 2L, 2L), .Label = c("Female",
"Male"), class = "factor"), AGE = c(20L, 20L, 15L, 16L, 13L),
BOTTLE_CNT = c(3L, 0L, 0L, 1L, 2L), QUALIFICATION_DESC = structure(c(2L,
2L, 1L, 2L, 2L), .Label = c("12th and below", "Graduation"
), class = "factor")), .Names = c("Gender", "AGE", "BOTTLE_CNT",
"QUALIFICATION_DESC"), class = "data.frame", row.names = c(NA,
-5L))
What I want is, if I select Gender in the first selectInput, the options Male and Female should be rendered in the second selectInput automatically.
I am not getting the factors rendered. Not sure where I a going wrong.
Upvotes: 0
Views: 106
Reputation: 4069
Add ID of the first selectInput to second observe:
observe({
input$filt, updateSelectInput(
session, "filt1",
choices = sort(as.character(unique(s()$input$filt))))
})
Probably this will help.
Upvotes: 0