英文:
How can I make a tab of a shinydashboard invisible?
问题
我尝试使用CSS样式(对按钮有效)来隐藏以下应用程序的第三个选项卡:
library(shiny)
library(shinydashboard)
library(shinyDashboardPlus)
library(shinyjs)
ui <- dashboardPage(
dashboardHeader(),
dashboardSidebar(
sidebarMenu(
id = "tabs", # 为侧边栏菜单设置一个ID
menuItem("选项卡1", tabName = "tab1"),
menuItem("选项卡2", tabName = "tab2"),
menuItem("隐藏选项卡", tabName = "invisible_tab", style = "visibility: hidden;")
)
),
dashboardBody(
tabItems(
tabItem(
tabName = "tab1",
useShinyjs()
),
tabItem(
tabName = "tab2",
useShinyjs(),
h3("选项卡2")
),
tabItem(
tabName = "invisible_tab",
h3("隐藏选项卡内容")
)
)
)
)
server <- function(input, output, session) {
}
shinyApp(ui, server)
选项卡的内容不会显示,但选项卡的标题仍然显示在侧边栏中...我如何使它隐藏,就像它不存在一样?
英文:
I've tried using CSS styling (that works on buttons) to hide the third tab of the following app:
library(shiny)
library(shinydashboard)
library(shinyDashboardPlus)
library(shinyjs)
ui <- dashboardPage(
dashboardHeader(),
dashboardSidebar(
sidebarMenu(
id = "tabs", # Set an ID for the sidebar menu
menuItem("Tab 1", tabName = "tab1"),
menuItem("Tab 2", tabName = "tab2"),
menuItem("Invisible Tab", tabName = "invisible_tab", style = "visibility: hidden;")
)
),
dashboardBody(
tabItems(
tabItem(
tabName = "tab1",
useShinyjs()
),
tabItem(
tabName = "tab2",
useShinyjs(),
h3("tab2")
),
tabItem(
tabName = "invisible_tab",
h3("Invisible Tab Content")
)
)
)
)
server <- function(input, output, session) {
}
shinyApp(ui, server)
The content of the tab is not displayed, but the title of the tab remains in the sidebar... How can I hide it just as is did not exist?
答案1
得分: 1
所有`menuItem`都由一个带有`href`属性的`<a>`标签定义,该属性构造为`#shiny-tab-[tabName]`,其中`tabName`是`menuItem`的相应参数。
因此,如果你使用以下方式定义你的`menuItem`:
menuItem("Invisible Tab", tabName = "invisible_tab")
那么你可以应用以下`CSS`:
a[href = '#shiny-tab-invisible_tab']{
visibility: hidden;
}
以使其不可见。
library(shiny)
library(shinydashboard)
library(shinydashboardPlus)
library(shinyjs)
ui <- dashboardPage(
dashboardHeader(),
dashboardSidebar(
tags$head(tags$style(HTML("
a[href = '#shiny-tab-invisible_tab']{
visibility: hidden;
}
"))),
sidebarMenu(
id = "tabs", # 为侧边栏菜单设置一个ID
menuItem("Tab 1", tabName = "tab1"),
menuItem("Tab 2", tabName = "tab2"),
menuItem("Invisible Tab", tabName = "invisible_tab")
)
),
dashboardBody(
tabItems(
tabItem(
tabName = "tab1",
useShinyjs()
),
tabItem(
tabName = "tab2",
useShinyjs(),
h3("tab2")
),
tabItem(
tabName = "invisible_tab",
h3("Invisible Tab Content")
)
)
)
)
server <- function(input, output, session) {
}
shinyApp(ui, server)
英文:
All menuItem
are defined by an <a>
tag with an href
attribute which is constructed as #shiny-tab-[tabName]
, where tabName
is the corresponding parameter of menuItem
.
Hence if you define your menuItem
using
menuItem("Invisible Tab", tabName = "invisible_tab")
then you can apply the CSS
a[href = '#shiny-tab-invisible_tab']{
visibility: hidden;
}
for setting it unvisible.
library(shiny)
library(shinydashboard)
library(shinydashboardPlus)
library(shinyjs)
ui <- dashboardPage(
dashboardHeader(),
dashboardSidebar(
tags$head(tags$style(HTML("
a[href = '#shiny-tab-invisible_tab']{
visibility: hidden;
}
"))),
sidebarMenu(
id = "tabs", # Set an ID for the sidebar menu
menuItem("Tab 1", tabName = "tab1"),
menuItem("Tab 2", tabName = "tab2"),
menuItem("Invisible Tab", tabName = "invisible_tab")
)
),
dashboardBody(
tabItems(
tabItem(
tabName = "tab1",
useShinyjs()
),
tabItem(
tabName = "tab2",
useShinyjs(),
h3("tab2")
),
tabItem(
tabName = "invisible_tab",
h3("Invisible Tab Content")
)
)
)
)
server <- function(input, output, session) {
}
shinyApp(ui, server)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论