how to hide/display items in dashboardBody based on radioGroupButton choices

Hi,

I trying to create this dashboard with following structure. It has 3 levels
Menu1: has 2 sub menus (Sub Menu 1 and Sub Menu2)
Menu2 has 2 sub menus (Sub Menu 3 and Sub Menu4)
The body has radioGroupButton that has 2 choices

  1. Choice 1
  2. Choice 2

So now the user when clicks
Sub Menu1 and clicks Choice 1 then display #A1
Sub Menu1 and clicks Choice 2 then display #A2
Sub Menu2 and clicks Choice 1 then display #A3
Sub Menu2 and clicks Choice 2 then display #A4
Likewise for sub menu 3 and 4.
I want #A1...A8 to hide or display based on the selection on Choice 1 or Choice 2.
I didnt know how to show or hide the fluidRows (#A1- #A8). Please advise.

library(shiny)
library(shinydashboard)
library(shinythemes)
library(shinyWidgets)
library(dplyr)
library(lubridate)
library(tidyverse)
library(data.table)
library(shinydashboardPlus)

ui= dashboardPagePlus(skin="purple-light",dashboardHeader(title="Testing"),
dashboardSidebar(width=200,
sidebarMenu(
menuItem("Menu1", tabName = "dashboard",startExpanded = TRUE,
menuSubItem("Sub Menu1", tabName = "sub1"),
menuSubItem("Sub Menu2", tabName = "sub2")),
menuItem("Menu2", tabName= "Widgets",startExpanded = TRUE,
menuSubItem("Sub Menu3", tabName = "sub3"),
menuSubItem("Sub Menu4", tabName = "sub4")))),

dashboardBody(radioGroupButtons("rb1",label=NULL, choices = c("choice1","choice2"), selected= "choice1",
individual= TRUE,status="info", justified= TRUE ,direction= "horizontal"),

tabItems(
tabItem("sub1",title= "Tab1",
fluidRow(plotOutput("plotgraph1")), #A1
fluidRow(plotOutput("plotgraph2"))), #A2
tabItem("sub2", title= "Tab2",
fluidRow(plotOutput("plotgraph3")), #A3
fluidRow(plotOutput("plotgraph1"))), #A4
tabItem("sub3", title= "Tab3",
fluidRow(plotOutput("plotgraph3")), #A5
fluidRow(plotOutput("plotgraph2"))), #A6
tabItem("sub4", title= "Tab4",
fluidRow(plotOutput("plotgraph1")), #A7
fluidRow(plotOutput("plotgraph1")) )))), #A8

server = function(input,output){
set.seed(1234)
pt1 <- qplot(rnorm(500),fill=I("red"),binwidth=0.2,title="plotgraph1")
pt3 <- qplot(rnorm(600),fill=I("blue"),binwidth=0.2,title="plotgraph3")
pt2 <- reactive({
input$rb1
if (input$rb1 =="choice1"){
return(qplot(rnorm(500),fill=I("blue"),binwidth=0.2,title="plotgraph2"))
} else {
return(NULL)
}
})
output$plotgraph1 = renderPlot({pt1})
output$plotgraph2 = renderPlot({pt2()})
output$plotgraph3 = renderPlot({pt3})
})
)

Please someone help me here.

No takers from R Shiny community who could resolve my issue....I feel its simple, but not sure how to do it. Please guys I need your valuable suggestion...Help me out.

You could use the shinyjs package to hide and show elements based on click events. Have a look at the example app and code explanations at the below page:

1 Like

Thanks for your help, trying to fix my code. If unable to will reach out to you.