JohnBones JohnBones
JohnBones JohnBones

Reputation: 343

In Shiny/R why my lis with purrr::map()t is not working in module?

This is my module file:

library(semantic.dashboard)

example_UI <- function(id) {
  ns <- NS(id)
  tagList(

    # 1:5 %>% map(~ list(menu = list(paste0(.x)),
    #                    content =list(paste0(.x))))

      list(menu = list('B'),
                content = list('B')),
    list(menu = list('C'),
         content = list('C')),
    list(menu = list('A'),
         content = list('A')),
    list(menu = list('A'),
         content = list('A')),
    list(menu = list('A'),
         content = list('A'))

  )
}

example_Server <- function(id) {
  moduleServer(
    id,
    function(input, output, session) {

    }
  )
}

When I run the code without using the purrr::map() function the panels labels are created well.

But when I try to create the panel labels with purrr::map() function it is not created

Bellow Is my shiny App

ui <- dashboardPage(
  dashboardHeader(color = "blue"),
  dashboardSidebar(side = "left", size = "thin", color = "teal",
                   sidebarMenu(
                     menuItem(tabName = "tab1", "Tab 1"))),
  dashboardBody(tabItems(

    tabItem(tabName = "tab1",

            tabBox(
              collapsible = FALSE,
              title = "Pull",
              color = "black",
              width = 16,

              tabs = example_UI('question')
              )

            )))
)

server <- function(input, output) {
}

shinyApp(ui, server)

What am I doing wrong?

Upvotes: 1

Views: 55

Answers (1)

MrFlick
MrFlick

Reputation: 206263

Your map() function returns a list() of length 5. It does not return five separate lists like you are using when calling tagList() without the map. In order to expand that single list into different paraemters, you can use !!!. For example

tagList(
  !!!(1:5 %>% map(~ list(menu = list(paste0(.x)),
                     content =list(paste0(.x))))
))

Upvotes: 2

Related Questions