Thank you, this is very helpful!
However, to get the full way there (and have the choices column of the data frame be reflected in the selection for each radioButton, I took your example a set further using map2, and you could use pmap and so on:
library(shiny)
library(tidyverse)
library(purrr)
choices <- c("Yes", "No", "Maybe")
df <- tibble(
car = rownames(mtcars),
choices = sample(choices, 32, T),
inames = tolower(gsub(" ", "", rownames(mtcars)))
)
ui <- fluidPage(
sidebarLayout(
sidebarPanel(uiOutput("radioholder")),
mainPanel(
textOutput("value"),
tags$style(type = "text/css", "#value {white-space: pre-wrap;}")
) ## to respect \n linebreaks
)
)
server <- function(input, output) {
output$radioholder <- renderUI({
map2(df$car, df$choices, ~ {
radioButtons(.x,
label = h5(.x),
choices = choices,
selected = .y, inline = T
)
})
})
output$value <- renderText({
printfunc <- function(x) {
paste0(
"radio ",
x,
" is set to ",
input[[x]]
)
}
paste0(map(df$inames, printfunc), collapse = "\n")
})
}
# Run the application
shinyApp(ui = ui, server = server)