Shiny Radio Button ChoiceName Output

Quick question that I haven't been able to answer from after much searching around. I have a named list being used as the options for a radiobutton selection. Is it right that the reactive selection only outputs the value, and not the name as well?

I want to use the value name as the title for a ggplot and can probably setup a lookup to re-match this, but just wanted to check there isn't a way to just get it directly from the reactive variable.

Thanks for any thoughts.

List of Options

    graph_options <- c("ukhpi", "avprice", "volume")
    graph_option_names <- c("House Price Index", "Average Price", "Volume of Transactions")
    graph_options <- setNames(graph_options, graph_option_names)

Radio Buttons Code in UI

                                 "Select Metric",
                                 choices = graph_options

It's a named vector, not a named list.

e.g. graph_options = c("First" = "a", "Second" = "b", "Third" = "c")

Yes radioButtons will show the names in the interface ("First", "Second", "Third"), and input$metric will be the value of the item selected (e.g. "a").

You can retrieve the corresponding name with names(graph_options)[graph_options==input$metric]

Thank you, good to know I wasn't missing anything on the radioButton function. The corresponding name code was very helpful - it would have taken me a while to puzzle that one through. Also helpful to know the correct terminology, often I struggle to find solutions by searching because I'm not sure what I am searching for.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.