Shiny 在闪亮的仪表板HeaderPlus中隐藏下拉按钮
我有一个Shiny 在闪亮的仪表板HeaderPlus中隐藏下拉按钮,shiny,shinydashboard,shinyjs,Shiny,Shinydashboard,Shinyjs,我有一个shinydashboardPlus,标题中有两个下拉按钮。每个按钮都对应一个选项卡,我想隐藏其选项卡未选中的按钮。我在下面提供了一个简单的工作示例。提前谢谢你 library(shiny) library(shinydashboard) library(shinydashboardPlus) library(shinyjs) ui <- shinyUI( dashboardPagePlus( dashboardHeaderPlus( left_menu
shinydashboardPlus
,标题中有两个下拉按钮。每个按钮都对应一个选项卡,我想隐藏其选项卡未选中的按钮。我在下面提供了一个简单的工作示例。提前谢谢你
library(shiny)
library(shinydashboard)
library(shinydashboardPlus)
library(shinyjs)
ui <- shinyUI(
dashboardPagePlus(
dashboardHeaderPlus(
left_menu = tagList(
dropdownButton(
inputId = "select_company_button",
label = "Select Company",
icon = icon("store"),
circle = FALSE,
selectizeInput(
inputId = "select_company",
label = "Company",
multiple = TRUE,
choices = c("ALL Companies" = ""),
selected = NULL,
options = list(
closeAfterSelect = TRUE,
plugins = list("remove_button")))
),
dropdownButton(
inputId = "select_industry_button",
label = "Select Industry",
icon = icon("industry"),
circle = FALSE,
selectizeInput(
inputId = "select_industry",
label = "Industry",
multiple = TRUE,
choices = c("ALL Industries" = ""),
selected = NULL,
options = list(
closeAfterSelect = TRUE,
plugins = list("remove_button")))
)
)
),
dashboardSidebar(
sidebarMenu(
id = "tabs",
menuItem(
text = "Company",
tabName = "company",
icon = icon("store")
),
menuItem(
text = "Industry",
tabName = "industry",
icon = icon("industry")
)
)
),
dashboardBody(
tabItems(
tabItem("company"),
tabItem("industry")
)
)
)
)
server <- shinyServer(function(input, output, session) {
observe({
if(input$tabs == "company") {
#show company dropdown button
#hide industry dropdown button
} else{
#hide company dropdown button
#show industry dropdown button
}
})
})
shinyApp(ui = ui, server = server)
库(闪亮)
图书馆(shinydashboard)
图书馆(shinydashboardPlus)
图书馆(shinyjs)
ui使用renderUI
应该可以做到这一点。试试这个
library(shiny)
library(shinydashboard)
library(shinydashboardPlus)
library(shinyjs)
ui <- shinyUI(
dashboardPagePlus(
dashboardHeaderPlus(
left_menu = tagList(
uiOutput("tab1")
)
),
dashboardSidebar(
sidebarMenu(
id = "tabs",
menuItem(
text = "Company",
tabName = "company",
icon = icon("store")
),
menuItem(
text = "Industry",
tabName = "industry",
icon = icon("industry")
)
)
),
dashboardBody(
tabItems(
tabItem("company"),
tabItem("industry")
)
)
)
)
server <- shinyServer(function(input, output, session) {
output$tab1 <- renderUI({
if(input$tabs == "company") {
dropdownButton(
inputId = "select_company_button",
label = "Select Company",
icon = icon("store"),
tabName = "company",
circle = FALSE,
selectizeInput(
inputId = "select_company",
label = "Company",
multiple = TRUE,
choices = c("ALL Companies" = ""),
selected = NULL,
options = list(
closeAfterSelect = TRUE,
plugins = list("remove_button")))
)
#show company dropdown button
#hide industry dropdown button
} else{
dropdownButton(
inputId = "select_industry_button",
label = "Select Industry",
icon = icon("industry"),
circle = FALSE,
selectizeInput(
inputId = "select_industry",
label = "Industry",
multiple = TRUE,
choices = c("ALL Industries" = ""),
selected = NULL,
options = list(
closeAfterSelect = TRUE,
plugins = list("remove_button")))
)
#hide company dropdown button
#show industry dropdown button
}
})
})
shinyApp(ui = ui, server = server)
库(闪亮)
图书馆(shinydashboard)
图书馆(shinydashboardPlus)
图书馆(shinyjs)
ui是否有其他方法可以做到这一点,而不必每次用户切换选项卡时都使用renderUI?我仍然希望selectizeInputs存在,以便可以访问它们的值,但我希望它们对用户隐藏。在我真正的应用程序中,我有四个选项卡和selectizeInput,所以只需通过javascript隐藏它们就好了。我对javascript不太熟悉。用户输入可以使用服务器端的selectizeInput完成。