【问题标题】:hideTab in a shiny module闪亮模块中的 hideTab
【发布时间】:2023-04-09 21:20:02
【问题描述】:

我有一个使用 navbarPage 布局的闪亮应用。应用程序中的每个选项卡都是一个闪亮的模块,每个选项卡都有各种子选项卡。基于用户登录,某些选项卡/子选项卡需要隐藏。由于这些是模块,我不确定如何实现这一点。这是一个不起作用的玩具示例。我的目的是隐藏名为“Second DB Panel”的选项卡面板

library(shiny)

#Module for first tab
mod_home_tab_ui <- function(id) {
  ns <- NS(id)
  tabPanel(
    title = 'Home',
    value = 'home',
    tabsetPanel(
      id = ns('first_set'),
      tabPanel('First Home Panel'),
      tabPanel('Second Home Panel')
    )
  )
}

mod_home_tab_server <- function(id) {
  moduleServer(id, function(input, output, session) {
    
  })
}

#Module for second tab
mod_second_tab_ui <- function(id) {
  ns <- NS(id)
  tabPanel(
    title = 'Dashboards',
    value = 'db',
    tabsetPanel(
      id = ns('second_set'),
      tabPanel('First DB Panel'),
      tabPanel('Second DB Panel')
    )
  )
}

mod_second_tab_server <- function(id) {
  moduleServer(id, function(input, output, session) {
    
  })
}

#Shiny App
ui <- navbarPage(
  "example",
  id = "all_tabs",
  mod_home_tab_ui('home_tab'),
  mod_second_tab_ui('second_tab')
)

server <- function(input, output, session){
  
  # Logic to read in the username and then hide tabs:
  hideTab('second_set', 'Second DB Panel', session = getDefaultReactiveDomain())
  
  mod_home_tab_server('home_tab')
  mod_second_tab_server('second_tab')
}

shinyApp(ui, server)

这可能与将正确的会话信息传递给hideTab 函数有关,但我不知道该怎么做。

【问题讨论】:

  • 错别字。应用 UI 中的 home-tabsecond_tab 以及应用服务器中对 hideTab 的调用中的 home_tabsecond_set
  • @Limey 谢谢纠正。对于hideTab,我指的是tabsetPanelid,其中包含我要隐藏的tabPanel。因此second_set 这是行不通的。

标签: r shiny


【解决方案1】:

如果tabsetPanelid 没有命名空间就可以工作:

tabsetPanel(
      id = 'second_set',
      tabPanel('First DB Panel'),
      tabPanel('Second DB Panel')
    )

【讨论】:

    猜你喜欢
    • 2017-12-09
    • 2021-07-17
    • 2018-05-11
    • 2021-11-09
    • 1970-01-01
    • 2020-09-30
    • 2021-01-10
    • 2019-01-18
    • 2019-09-01
    相关资源
    最近更新 更多