R Shinydashboard:如何用selectInput()(过滤器)折叠menuItem()?

时间:2016-10-21 14:23:20

标签: r shiny

我想将Shinydashboard输入字段显示为一种menuSubItem,但是我发现很难编写解决方案。

  • 家庭渗透(点击下拉菜单)
    • 存储滤波器
    • 按钮
  • 销售(家庭渗透菜单在点击和销售菜单下降时崩溃)
    • 过滤器x

你有解决方法吗?

ui.R

library(shiny)
library(shinydashboard)
library(leaflet)

source("R/load_metadata.R", chdir=TRUE)


# Header of the  dashboard
header <- dashboardHeader(
  title = "x",
  titleWidth = 350,
  dropdownMenuOutput("task_menu")

  )


# Sidebar of the dashboard
sidebar <- dashboardSidebar(
  sidebarMenu(
    id = "menu_tabs",
    menuItem("Household Penetration", tabName = "menutab1", icon = icon("percent")),
        selectInput("storeInput", label = "Store",
                     choices = STOREFILTER$STORE_NAME,
                     selected = STOREFILTER$STORE_NAME[1]),
        actionButton("Button", "Filter Map"),
    menuItem("Sales", tabName = "menutab2", icon = icon("euro"))
  )
)


# Body of the dashboard
body <- dashboardBody(
  tabItems(
    tabItem(
      tabName = "menutab1",
      tags$style(type = "text/css", "#mymap {height: calc(100vh - 80px) !important;}"),
      leafletOutput("mymap")),
    tabItem(
      tabName = "menutab2",
      tags$style(type = "text/css", "#mymap {height: calc(100vh - 80px) !important;}"),
      h2("Dashboard tab content")
    )
  )
)


# Shiny UI
ui <- dashboardPage(
  header,
  sidebar,
  body,
  tags$head(
    tags$style(HTML(type='text/css', "#Button { width:40%; margin-left: 30%; margin-right: 30%; background-color: #3C8DBC; color: black; font-weight: bold; border: 0px}")))
)

1 个答案:

答案 0 :(得分:0)

根据所选菜单,您可以使用conditionalPanel显示/隐藏输入字段:

conditionalPanel(
  condition = "input.menu_tabs == 'menutab1'",
  selectInput("storeInput", label = "Store",
              choices = STOREFILTER$STORE_NAME,
              selected = STOREFILTER$STORE_NAME[1]),
  actionButton("Button", "Filter Map")
)