shiny: start the app with hidden tabs, with NO delay

前端 未结 4 1336
一个人的身影
一个人的身影 2020-12-15 13:24

I would like to build an application and some of the tabs will be hidden to the user until he types the right password. I know how to do this with shinyjs::hideTab

4条回答
  •  长情又很酷
    2020-12-15 14:05

    I'd go with renderUI (see @BertilBaron's answer) or appendTab because it's easy to bypass the password when hiding the tabs:

    Here is how to achive the desired behaviour via appendTab avoiding the above with basic shiny, no additional JS:

    library(shiny)
    
    ui <- fluidPage(navbarPage("hello", id = "hello",
      tabPanel(
        "home",
        br(),
        h3("this is home"),
        passwordInput("pass", "enter 'password' to see the tabs: "),
        actionButton("enter", "enter")
      )
    ))
    
    server <- function(input, output, session) {
      observeEvent(input$enter, {
        if (input$pass == "password") {
          appendTab(inputId = "hello", tab = tabPanel("tab2", value = "tab2_val", br(), h4("this is tab2")))
          appendTab(inputId = "hello", tab = tabPanel("tab3 with a lot of stuff in it",value = "tab3_val", br(), h4("this is tab3")))
        }
      })
    }
    
    shinyApp(ui, server)
    

提交回复
热议问题