-
I've always worked with the default Shiny UI until last week, so apologies if this is a trivial question. Before tabPanel(
HTML(
"<span id='disabled_tab' alt='En cours'>De l'enseignement vers le marché du travail</span>"
),
icon = icon("briefcase")
) and then tags$script(
HTML(
"
$(document).ready(function() {
$('#disabled_tab').parent('a').removeAttr('href').css({'pointer-events': 'none', 'color': '#777'});
});"
)
) but it looks like it's not an option anymore. What's the best way to achieve this result with |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
Can you describe the behavior you're wanting or expecting from the disabled tab? Should it be clickable? Does the tab content show up? Do you just want a faded icon in the navbar? etc. |
Beta Was this translation helpful? Give feedback.
-
This is the solution I found. 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.onclick = function(e) { e.preventDefault(); };
}
}, 500);
"
))
),
page_navbar(
navset_tab(
id = "nav",
nav_panel("Tab 1", value = "tab1", "This is tab 1"),
nav_panel("Tab 2", value = "tab2", "This is tab 2 (should be disabled)")
)
)
)
server <- function(input, output, session) {
}
shinyApp(ui, server) |
Beta Was this translation helpful? Give feedback.
This is the solution I found.
I could be happy with it, but is there a solution that doesn't involve injecting JavaScript?