Shiny Hierarchical Menu implementation

Source: Internet
Author: User
The main purpose of this paper is to implement the hierarchical menu in R shiny

After you select Region A, select the store in area a (only the a area stores in the dropdown option) to achieve the effect

Code

Global. R

Options (Stringsasfactors=false, scipen=10, digits=4)

Library (DPLYR)

df_sample <-data.frame (Region=rep ( Letters[1:3], 4),
                        Store=paste (Rep (Letters[1:3], 4), 1:4, sep= ""),
                        result=sample (1:100,)) region
<- Unique (df_sample$region)

Ui. R

Library (shiny)
library (Shinydashboard)

Shinyui (
  dashboardpage (
    dashboardheader (title = "Tiered Menu"),

    Dashboardsidebar (
      sidebarmenu (
        selectinput ("Region", "area:", 
                    choices = regions),

        uioutput ("SLT _store "),

        menuItem (" Grading Menu ", tabname =" Tab_budget ", Icon = icon (" gear "))
    ,


    dashboardbody (
      TabItems (
        tabItem (tabname = "Tab_budget",
                fluidrow (
                  # Raw data
                  box (H1 ("raw Data"),
                      tableoutput (" Df1 ")),

                  # Filter results
                  Box (H1 (" Filter Results "),
                      tableoutput (" DF2 "
)))))))

Server. R

library (shiny) library (shinydashboard) shinyserver (function (input, output) {store_t <-R Eactive ({df_sample%>% filter (region = = input$region)%>% Select (Store)}) # in Server. R in use Renderui Output$slt_store <-Renderui ({selectinput ("store", "Store:", choices = store_t () $store)}) output $DF 1 <-rendertable ({df_sample%>% Arrange (region, store)}) output$df2 <-rendertable ({DF _sample%>% filter (region = = input$region)%>% filter (store = = Input$store)}) 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.