Skip to content

How to disable a bslib::nav_panel #1202

Answered by fzenoni
fzenoni asked this question in Q&A
Discussion options

You must be logged in to vote

This is the solution I found.
I could be happy with it, but is there a solution that doesn't involve injecting JavaScript?

library(shiny)
library(bslib)
library(shinyjs)

ui <- tagList(
  useShinyjs(),
  tags$head(
    tags$style(HTML(
      "
      a.nav-link.disabled {
        pointer-events: none;
        opacity: 0.5;
      }
    "
    )),
    tags$script(HTML(
      "
      // Wait a bit for the tabs to be rendered
      setTimeout(function() {
        const tab = document.querySelector(\"a[data-value='tab2']\");
        if (tab) {
          tab.classList.add('disabled');
          tab.setAttribute('tabindex', '-1');
          tab.setAttribute('aria-disabled', 'true');
          tab.…

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
1 reply
@fzenoni
Comment options

Comment options

You must be logged in to vote
2 replies
@gadenbuie
Comment options

@fzenoni
Comment options

Answer selected by fzenoni
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants