Hello,
Say I have an existing data frame, and I want to create a succession of radioButton inputs to replicate this data, how do I / can I do this without copying and pasting and changing [1] to [2] and so on?
See below for a reprex to demonstrate how I am currently doing it - is there a better way to create multiple input elements from a dataframe/vector/list?
library(shiny)
library(tidyverse)
choices <- c("Yes", "No", "Maybe")
df <- tibble(car = rownames(mtcars),
choices = sample(choices, 32, T))
ui <- fluidPage(
radioButtons(df$car[1], label = h5(df$car[1]),
choices = choices,
selected = df$choices[1], inline = T),
radioButtons(df$car[2], label = h5(df$car[2]),
choices = choices,
selected = df$choices[2], inline = T),
radioButtons(df$car[3], label = h5(df$car[3]),
choices = choices,
selected = df$choices[3], inline = T),
)
server <- function(input, output) {
output$value <- renderPrint({ input$radio })
}
# Run the application
shinyApp(ui = ui, server = server)