I try to dynamically create an accordion bast on a dataframe. Despite many try-outs I did not manage to get it working. Below the code of an example dashboard with two examples:
- lappy: not working (lijst1)
- program each item: working (lijst2)
see example below.
Hopefully someone can help?
library(bs4Dash)
library(shiny)
dataset <- data.frame(
title = c("title 1", "title 2")
, tekst = c("text 1", "text 2")
)
# create using lapply (flexible)
lijst1 <- accordion(
id = "test1"
, lapply(seq_along(dataset$title), function(i){
accordionItem(title = dataset$title[i], dataset$tekst[i])
})
)
# create by specify each item
lijst2 <- accordion(
id = "test2"
, accordionItem(title = "title 1 simple", "text 1 simple")
, accordionItem(title = "title 1 simple", "text 2 simple")
)
ui <- dashboardPage(
dashboardHeader()
, dashboardSidebar()
, dashboardBody(
h2("Doesn't work")
, lijst1
, h2("Works")
, lijst2
)
)
server = function(input, output) {}
shinyApp(ui = ui, server = server)