using purr:: map across a data_frame with a list column

I am trying to use purr map function or its variants to map data across multiple functions of R-Shiny. I have a complicated structure. I am trying to wrap output in R shiny division of tabitems. I have my contents stored in example.json.

{
  "Section_1": {
    "MainHeader": [{
      "School": "Montessori"
    }],
    "boxitems": [{
        "tabName": "id1",
        "box": [{
            "title": "Student graph",
            "custofun": ["Bob", "Dan", "Sean"]
          },
          {
            "title": "Teacher graph",
            "custofun": ["Robinson"]
          }
        ]
      },
      {
        "tabName": "id2",
        "box": [{
            "title": "Student graph",
            "custofun": ["Felix", "Helix", "Alex"]
          },
          {
            "title": "Teacher graph",
            "custofun": ["Phelix"]
          }
        ]
      }
    ]
  }
}

I read this into df format

json <- fromJSON("example.json")

I am trying to generate the TabItems and its boxes dynamically by wrapping them in map function, for example to just map on tabItem values I can do this

 map(unique(list_df$id), ~ tabItem(tabName = .x)) 

Unable to figure out on how to do a nested map where I need to traverse through ID -> list -> list. Tried the other variants like pmap but could not solve it.

For example, For id1 I have 2 boxes and calling respective custom functions (Bob, Dan) etc to plot respective student graph in the box. When we hard code, it looks like below.

library(shiny)
library(shinydashboard)

tabItem(
  tabName = "id1",
  box(        
    title = "Students graph",
    column(width = 2, Bob("id1")),
    column(width = 12, Dan("id1")),
    column(width = 4, Sean("id1"))
  ),
  box(        
    title = "Teacher graph",
   column(width = 12, Robinson("id1"))
  )
)

Here is my attempt, I named the list items with respective ids. Trying to use map for function Tabitem, then map2 to map two items to box variables. The function does not work as expected, just the Tabitems are rendered as output below. However, 1) the boxes are not rendered. 2) Maybe I also need to add a condition to find out exactly how many boxed are needed and how many functions to be called under each box. So, could not either yet. Appreciate suggestions and help.

json$Section_1$boxitems %>% as.tibble() # to check the strucutre
df <- json$Section_1$boxitems %>% select(tabName,box)
df$box <- setNames(df$box,df$tabName)


BoxCustomFunc <- function(tabName,box) {
   map(tabName , ~ tabItem(tabName = .x),
   map2(x = box, y = box[tabName],
         box(title = .x$title, 
      column(width = 2, get(.y$custofun)(tabName)))
    ))
}

current output

[[1]]
<div role="tabpanel" class="tab-pane" id="shiny-tab-id1"></div>

[[2]]
<div role="tabpanel" class="tab-pane" id="shiny-tab-id2"></div>

Another approach, with a clumsy loop. I am not in favor for nested loops, but on second thought it is not a calculation, just pasting html function tags together, so maybe should be OK ? This does not work as intended.

BoxCustomFunc <- function(df) {
  tab <- list()
  box <- list()
  col <- list()
  for (id in 1:length(df$tabName)) {
    tab <- tabItem(tabName = df$tabName[id])
    for (nbox in 1:length(df$box[id])) {
      # print(df$box[id])
      box <- box(
        title = df$box[[id]]["title"][nbox],
        # print(df$box[[id]]["title"][nbox]),
        for (cusfun in 1:length(df$box[[id]]["custofun"][[nbox]][nbox])) {
          # print(df$box[[id]]["custofun"][[nbox]][nbox])
          col <-
            column(width = 2, get(df$box[[id]][["custofun"]][[nbox]][cusfun])(df$tabName[i]))
        }
      )
    }
    return(tab)
  }
}


BoxCustomFunc(df)

if I use print, it throws the following error. cat and return does not handle lists. Any suggestions are welcome.

Error in if (browse) html_print(x) else print(HTML(as.character(x)), ...) : argument is not interpretable as logical