Reputation: 13500
I am new to R Shiny and I am trying to create an app which I need it to be as interactive as possible. One problem that I am dealing with is this. In the ui.R I have the following:
helpText("Select a feature"),
uiOutput("sliders")
And in the server.R:
output$sliders <- renderUI({
selectInput('feature_name',
'Feature name', #Description
choice = c("F1"='1', "F2"='2'))
})
My question is that is it possible to change something in renderUI so that instead of setting c("F1"='1', "F2"='2')) statically I can pass the results of a function to it so it can be more dynamic (a function which generates a feature list based on something that user does and passes the list to renderUI to create the selectInput). Something like following:
output$sliders <- renderUI({
selectInput('feature_name',
'Feature name', #Description
choice = c(feature_creator(method)))
})
Where "feature_creator" is a function and it returns: "F1"='1', "F2"='2' based on the method selected by user (variable "method" is defined and I have the value). My question to be more specific is what should "feature_creator" return as output?
Hope my question is clear enough. Let me know if I should add anything to the problem description.
Any help will be much appreciated. Thanks
Upvotes: 0
Views: 681
Reputation: 12654
Assuming that all you really need is the method
argument, this is not hard.
1) Make a radioButtons()
input in your ui
that will let the user select a method, lets give it inputId="MethodChoice"
.
2) In your choice
argument in the selectInput
you should use choice=c(feature_creator(input$MethodChoice))
Then feature_creator
will get a text value based on the method the user chooses.
In order to work in choice
, feature_creator
should return a named list, similar in format to what you hard-coded.
Upvotes: 1