Update
I think I got it working.
My approach is: define two css styles in the beginning.
display: none
for the initial tab2 navbar tabsetpanel and display: inline-block !important
for a new class called 'showtab'. Then I use shinyjs to add a class to tab2 of the navbar tabsetpanel which overwrites (!important
) the original css style of tab2.
The problem with shinyjs original functions was:
(1) when using hide
/show
then you can see tab2 in the initial start up where you do not want it to show up.
(2) when using your css style display: none
and either shinyjs::show
or shinyjqui::jqui_show
then the style argument is changed to style = inline
which messes the position of the word "tab2" in the navbarpage up.
css <- "
#navbar li a[data-value = tab2] {
display: none;
}
.showtab {
display: inline-block !important;
}
"
#
library(shiny)
library(shinyjs)
ui <- tagList(
useShinyjs(),
inlineCSS(css),
navbarPage(
"test navbarPage",
id = "navbar",
tabPanel(
title = "tab1",
actionButton("show", "Show tab2")
),
tabPanel(
title = "tab2"
)
)
)
server <- function(input, output, session) {
observeEvent(input$show, {
addClass(selector = "#navbar li a[data-value = tab2]",
class = 'showtab')
})
}
shinyApp(ui = ui, server = server)