简体   繁体   中英

R Shinydashboard: how to collapse menuItem() with selectInput() (filters) in it?

I would like to display Shinydashboard input fields as a type of menuSubItem, however I'm finding it difficult to write the solution.

  • Household Penetration(dropdown on click)
    • Store-filters
    • Button
  • Sales(Household Penetration Menu collapses on click and Sales Menu drops)
    • filter x

Do you have any solution for this?

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}")))
)

You can show/hide your inputs fields with a conditionalPanel according to the selected menu:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM