tabitems inside a div

Hi all

I am trying to create tabitems inside a div and then render it as shown in below (Method 2)

Method 1 : (Direct Method)

library(shiny)
library(shinydashboard)
library(DT)


c_b <- div(tabItem(
      tabName = "menu1",dataTableOutput("tab")
    ),
    tabItem(
      tabName = "menu2",dataTableOutput("tab1")))
  

# Define UI for application that draws a histogram
ui <- dashboardPage(
  dashboardHeader(),
  dashboardSidebar(
    sidebarMenu(
      menuItem("menu1", tabName = "menu1", icon = icon("table")),
      menuItem("menu2", tabName = "menu2", icon = icon("table"))
    )
  ),
  dashboardBody(
    tabItems(
      tabItem(
        tabName = "menu1",dataTableOutput("tab")
      ),
      tabItem(
        tabName = "menu2",dataTableOutput("tab1"))
    )
  )
  
)

# Define server logic required to draw a histogram
server <- function(input, output, session) {
  
output$tab <- renderDataTable({
  datatable(iris)
})
  
output$tab1 <- renderDataTable({
  datatable(iris)
})
}

# Run the application 
shinyApp(ui = ui, server = server)

Method 2 :
Here instead of writing inside tabitems, I am creating a div. But not working

library(shiny)
library(shinydashboard)
library(DT)


c_b <- div(tabItem(
      tabName = "menu1",dataTableOutput("tab")
    ),
    tabItem(
      tabName = "menu2",dataTableOutput("tab1")))
  

# Define UI for application that draws a histogram
ui <- dashboardPage(
  dashboardHeader(),
  dashboardSidebar(
    sidebarMenu(
      menuItem("menu1", tabName = "menu1", icon = icon("table")),
      menuItem("menu2", tabName = "menu2", icon = icon("table"))
    )
  ),
  dashboardBody(
    tabItems(
      c_b
    )
  )
  
)

# Define server logic required to draw a histogram
server <- function(input, output, session) {
  
output$tab <- renderDataTable({
  datatable(iris)
})
  
output$tab1 <- renderDataTable({
  datatable(iris)
})
}

# Run the application 
shinyApp(ui = ui, server = server)

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.