bs4Dash icon indicating copy to clipboard operation
bs4Dash copied to clipboard

How to Show Tabpanels in bs4navbar() ?

Open kmaheshkulkarni opened this issue 4 years ago • 19 comments

kmaheshkulkarni avatar May 08 '20 08:05 kmaheshkulkarni

Do you mean a navbar navigation with tabs like for the sidebar?

DivadNojnarg avatar May 16 '20 17:05 DivadNojnarg

Do you mean navbar navigation with tabs like for the sidebar?

Yes Definitely

kmaheshkulkarni avatar May 17 '20 05:05 kmaheshkulkarni

@DivadNojnarg Have you got any solution on this?

kmaheshkulkarni avatar May 26 '20 05:05 kmaheshkulkarni

I don't have time to include it at the moment.

DivadNojnarg avatar May 27 '20 21:05 DivadNojnarg

I don't have time to include it at the moment.

No Problem man, Take your time Right now I use Button and drop-down button functions from Shinywidgets package

kmaheshkulkarni avatar Jun 05 '20 07:06 kmaheshkulkarni

I'll implement a better solution but here is a starting point:

library(shiny)
library(bs4Dash)

navbarTab <- function(tabName, ..., icon = NULL) {
  tags$li(
    class = "nav-item",
    tags$a(
      class = "nav-link",
      id = paste0("tab-", tabName),
      href = paste0("#shiny-tab-", tabName),
      `data-toggle` = "tab",
      `data-value` = tabName,
      icon,
      tags$p(...)
    )
  )
}


navbarMenu <- function(..., id = NULL) {
  if (is.null(id)) id <- paste0("tabs_", round(stats::runif(1, min = 0, max = 1e9)))
  
  tags$ul(
    class = "nav dropdown", 
    role = "menu",
    id = "sidebar-menu",
    ...,
    div(
      id = id,
      class = "sidebarMenuSelectedTabItem",
      `data-value` = "null",
      
    )
  )
}

shinyApp(
  ui = dashboardPage(
    header = dashboardHeader(
      navbarMenu(
        navbarTab(tabName = "Tab1", "Tab 1"),
        navbarTab(tabName = "Tab2", "Tab 2")
      )
    ),
    body = dashboardBody(
      tabItems(
        tabItem(
          tabName = "Tab1",
          "Tab 1"
        ),
        tabItem(
          tabName = "Tab2",
          "Tab 2"
        )
      )
    ),
    sidebar = dashboardSidebar()
  ),
  server = function(input, output, session) {
    
  }
)

DivadNojnarg avatar Dec 02 '20 22:12 DivadNojnarg

Hey @DivadNojnarg this works superbly Thanks for your support. I think you can add these methods to the package. I am designing one template on the basis of these navbar tabs. Will share with you soon

kmaheshkulkarni avatar Dec 03 '20 12:12 kmaheshkulkarni

Is there a navbar_light_active_color version for this approach?

fmmattioni avatar Dec 03 '20 12:12 fmmattioni

@fmmattioni : what do you mean?

DivadNojnarg avatar Dec 03 '20 13:12 DivadNojnarg

I was wondering if I could change the color of the navbar link. I was thinking something like this: https://dreamrs.github.io/fresh/articles/vars-bs4dash.html#navbar

fmmattioni avatar Dec 03 '20 13:12 fmmattioni

Sure with:

create_theme(
   bs4dash_vars("navbar-light-active-color" = "purple")
)

I also had to change the navbarMenu container class to navbar-nav so that it matches with the scss definition:

.navbar-nav {
    .nav-link {
      color: $navbar-light-color;

      @include hover-focus() {
        color: $navbar-light-hover-color;
      }

      &.disabled {
        color: $navbar-light-disabled-color;
      }
    }

    .show > .nav-link,
    .active > .nav-link,
    .nav-link.show,
    .nav-link.active {
      color: $navbar-light-active-color;
    }
  }
library(shiny)
library(bs4Dash)
library(fresh)

navbarTab <- function(tabName, ..., icon = NULL) {
  tags$li(
    class = "nav-item",
    tags$a(
      class = "nav-link",
      id = paste0("tab-", tabName),
      href = paste0("#shiny-tab-", tabName),
      `data-toggle` = "tab",
      `data-value` = tabName,
      icon,
      tags$p(...)
    )
  )
}


navbarMenu <- function(..., id = NULL) {
  if (is.null(id)) id <- paste0("tabs_", round(stats::runif(1, min = 0, max = 1e9)))
  
  tags$ul(
    class = "navbar-nav dropdown", 
    role = "menu",
    id = "sidebar-menu",
    ...,
    div(
      id = id,
      class = "sidebarMenuSelectedTabItem",
      `data-value` = "null",
      
    )
  )
}

shinyApp(
  ui = dashboardPage(
    freshTheme = create_theme(
      bs4dash_vars("navbar-light-active-color" = "purple")
    ),
    header = dashboardHeader(
      navbarMenu(
        navbarTab(tabName = "Tab1", "Tab 1"),
        navbarTab(tabName = "Tab2", "Tab 2")
      )
    ),
    body = dashboardBody(
      tabItems(
        tabItem(
          tabName = "Tab1",
          "Tab 1"
        ),
        tabItem(
          tabName = "Tab2",
          "Tab 2"
        )
      )
    ),
    sidebar = dashboardSidebar()
  ),
  server = function(input, output, session) {
    
  }
)

DivadNojnarg avatar Dec 03 '20 13:12 DivadNojnarg

This is great!!! Thanks a lot, @DivadNojnarg!

fmmattioni avatar Dec 03 '20 16:12 fmmattioni

Leave it open until it is implemented in core

DivadNojnarg avatar Dec 03 '20 16:12 DivadNojnarg

Hey @DivadNojnarg,

I have noticed that since a few commits, the above kind of breaks. For example, it doesn't show the home page anymore (need to click on the first tab to show), and once I click on another tab I can't go back anymore.

I have been using the following commit that still worked:

remotes::install_github("RinteRface/bs4Dash@d8cb044f267abb8162068c29e2d959ba520cd040")

But I was wondering what the issue is? I am sorry that I can't give more info 🤔

fmmattioni avatar Jan 30 '21 12:01 fmmattioni

@fmmattioni . As per latest {bs4Dash}: sidebar-menu became a class instead of an id, causing the break.

library(shiny)
library(bs4Dash)
library(fresh)

navbarTab <- function(tabName, ..., icon = NULL) {
    tags$li(
        class = "nav-item",
        tags$a(
            class = "nav-link",
            id = paste0("tab-", tabName),
            href = paste0("#shiny-tab-", tabName),
            `data-toggle` = "tab",
            `data-value` = tabName,
            icon,
            tags$p(...)
        )
    )
}


navbarMenu <- function(..., id = NULL) {
    if (is.null(id)) id <- paste0("tabs_", round(stats::runif(1, min = 0, max = 1e9)))
    
    tags$ul(
        class = "navbar-nav dropdown sidebar-menu", 
        role = "menu",
        ...,
        div(
            id = id,
            class = "sidebarMenuSelectedTabItem",
            `data-value` = "null",
            
        )
    )
}

shinyApp(
    ui = dashboardPage(
        freshTheme = create_theme(
            bs4dash_vars("navbar-light-active-color" = "purple")
        ),
        header = dashboardHeader(
            navbarMenu(
                navbarTab(tabName = "Tab1", "Tab 1"),
                navbarTab(tabName = "Tab2", "Tab 2")
            )
        ),
        body = dashboardBody(
            tabItems(
                tabItem(
                    tabName = "Tab1",
                    "Tab 1"
                ),
                tabItem(
                    tabName = "Tab2",
                    "Tab 2"
                )
            )
        ),
        sidebar = dashboardSidebar()
    ),
    server = function(input, output, session) {
        
    }
)

DivadNojnarg avatar Feb 03 '21 00:02 DivadNojnarg

Fantastic! Thanks a lot for looking into it, @DivadNojnarg !

fmmattioni avatar Feb 03 '21 07:02 fmmattioni

This is just great! Thanks!

shahreyar-abeer avatar Sep 06 '21 08:09 shahreyar-abeer

Thanks DivadNojnarg, i was searching this kind of thing in a modern way to do with shiny for a couple of days.

mikael04 avatar Sep 20 '21 10:09 mikael04

Thanks for this. Just a note to self (and others if interested) that some time in the future I want to build on this and make custom navigation tabs like this: https://css-tricks.com/tabs-with-round-out-borders/

jfunction avatar Jun 08 '22 09:06 jfunction

@DivadNojnarg Have you got any solution about tabpanel of dropdown, just like this in adminlte website. https://adminlte.io/docs/3.2/components/main-header.html image

duanyu5871 avatar Apr 12 '23 07:04 duanyu5871

Going to work on this again soon to get it in the function list.

DivadNojnarg avatar Jun 05 '23 15:06 DivadNojnarg