0

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

2
  • 1
    Short answer - yes you can do that, but without a more specific question it is hard to give a real answer. Commented Jul 22, 2015 at 18:57
  • @JohnPaul just edited the question, is it clear now? Commented Jul 22, 2015 at 19:01

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

John I edited my question again. The method is defined and the thing that I can not figure out is: what should feature_creator return so it looks like : "F1"='1', "F2"='2'. I have already tried returning it as a string which I am sure is incorrect and it is not working.
Awesome. Named list, thats what I have been looking for all day. Thanks John

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.