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