I have a simple shiny app adapted from an example I found online.
I want to either:
-Select option1 + only show tab1 (hide tab2)
or
-Select option2 + only show tab2 (hide tab1).
Here is the current code:
library(shiny)
library(shinyjs)
jscode <- '
shinyjs.init = function() {
$(".nav").on("click", ".disabled", function (e) {
e.preventDefault();
return false;
});
}'
css <- '
.disabled {
background: #eee !important;
cursor: default !important;
color: black !important;
}'
shinyApp(
ui = fluidPage(
useShinyjs(),
extendShinyjs(text = jscode, functions = "init"),
tags$style(css),
selectizeInput("foo", "Select an option", selected = NULL ,choices=c("Option1","Option2"), multiple = TRUE),
tabsetPanel(
id = "navbar",
tabPanel(title = "Option1",
value = "tab1",
h1("This is Option1")
),
tabPanel(title = "Option2",
value = "tab2",
h1("This is Option2")
)
)
),
server = function(input, output) {
observe(print(length(input$foo)==1))
observe({
toggleClass(selector = "#navbar li a[data-value=tab2]", class = "disabled",
condition = length(input$foo)==1)
})})