'How to disable tabpanel in the app deployed on shinyapps.io?

I have a problem disabling tabpanel in my shiny app. To do so, I tried the following code:

library(shiny)
library(shinyjs)

ui <- navbarPage("Hello",
                 tabPanel("Panel1",
                          useShinyjs()),
                 tabPanel("Panel2"),
                 tabPanel("Panel3")
)

server <- function(input, output, session) {
    disable(selector = '.navbar-nav a[data-value="Panel2"]')
    disable(selector = '.navbar-nav a[data-value="Panel3"]')
}

shinyApp(ui, server)


Everything is working fine, until I deploy the app on shinyapps.io. Then weird things happen - clicking on a tab refreshes the whole app or disabling does not work at all and the app lets me access the panel I want to block. You can see this behavior here

https://krystynagrzesiak.shinyapps.io/test_panel/

where I deployed the code I posted above.

I'm not very familiar with shinyjs. I tried to inspect the elements of panel in my browser and everything seems to be fine, all the ones I want to block contain class="disabled". I checked that on Firefox and Chrome and there is no difference.

I'm running out of ideas. Is there something I'm doing wrong? Is there any way of fixing it? Are there any other approaches that would work as I expect?

I would be very grateful for any help!



Solution 1:[1]

I have modified your example. I don't think you need to disable specific tabPanels by useShinyjs function disable. You could simply specify selectors in a separate css file, and set their property pointer-events to none.

# style.css
.navbar-nav a[data-value="Panel2"] {
  pointer-events: none;
}
.navbar-nav a[data-value="Panel3"] {
  pointer-events: none;
}

and R file

# app.R 
library(shiny)
library(shinyjs)

ui <- navbarPage("Hello",
                 includeCSS("./www/style.css"),
                 tabPanel("Panel1"),
                 tabPanel("Panel2"),
                 tabPanel("Panel3")
)

server <- function(input, output, session) {

}

shinyApp(ui, server)

Hopefully it will solve your problem.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1