How to disable a tabPanel in shinydashboard?
Asked Answered
I

1

6

Is there a way to disable a tabPanel until an actionButton is clicked? I tried to do this using shinyjs but that did not work. Currently my ui.R has the following code. I want to disable 'Filter' tabPanel until loadButton is clicked. `

body <- dashboardBody(
    useShinyjs(),
    tabsetPanel(id = "tabs", type = 'pills',
        tabPanel("Load", dataTableOutput("loadTab")),
        tabPanel("Filter", id='filterTab',dataTableOutput("filteredResults"))
    ))
sidebar <- dashboardSidebar(
        sidebarMenu(
         selectInput(inputId = "datasetName",label = 'Dataset',  choice=c('Cancer','Normal')),
         actionButton("loadButton", label = "Load")
        ))

` Any help is appreciated.

Israelitish answered 23/5, 2016 at 3:9 Comment(0)
I
6

I got it working with shinyjs. `

    jsCode <- "
shinyjs.disableTab = function() {
    var tabs = $('#tabs').find('li:not(.active) a');
    tabs.bind('click.tab', function(e) {
        e.preventDefault();
        return false;
    });
    tabs.addClass('disabled');
}
shinyjs.enableTab = function(param) {
    var tab = $('#tabs').find('li:not(.active):nth-child(' + param + ') a');
    tab.unbind('click.tab');
    tab.removeClass('disabled');
}

" ` And then enabling and disabling tabs as needed.

Israelitish answered 23/5, 2016 at 18:27 Comment(2)
I've been using your answer to enable and disable tabs as need but I realized that it doesn't work if the title in tabPanel() contains spaces in. How can your jsCode be modified to correct this issue?Jural
could you provide a MWE with ui and server functions ?Bridgid

© 2022 - 2024 — McMap. All rights reserved.