I have a shiny app below with 3 different tabs. I want each tab to have its own sidebar and I did this using conditionalPanel()
. The first tab though (InsiderTraining
) has 2 more tabs inside it (Tab1,Tab2
) which I also want to have separated sidebars.
library(shiny)
library(shinydashboard)
library(shinydashboardPlus)
shinyApp(
ui = tags$body(class="skin-blue sidebar-mini control-sidebar-open",dashboardPage(
options = list(sidebarExpandOnHover = TRUE),
header = dashboardHeader(title = "Investment Advisor Monitoring - Insider Trading",titleWidth = 450),
sidebar = dashboardSidebar(minified = F, collapsed = F,
h4("Investment Selected"),
uiOutput("mytab11"), uiOutput("mytab12"),uiOutput("mytab13"),uiOutput("mytab14")
#textInput("StockTicker3", "Enter Stock Symbol 3", value = "AMZN")
),
body = dashboardBody(
h3('Results'),
tabsetPanel(id = "tabs",
tabPanel("InsiderTraining",
tabsetPanel(id="tabs2",
tabPanel("tab1"),
tabPanel("tab2"))),
tabPanel("Switching"),
tabPanel("Tax Loss Harvesting")
)
),
controlbar = dashboardControlbar(width = 300,
h4("Insider Trading Parameters"),
uiOutput("mytab21"), uiOutput("mytab22")
#selectInput("InsiderTradingModel3", "Insider Trading Model 3",
# c("Dynamic" = "Dynamic",
# "AI based" = "AIbased"))
),
title = "DashboardPage"
)),
server = function(input, output) {
output$mytab11 <- renderUI({
tagList(
conditionalPanel(condition = 'input.tabs=="InsiderTraining"',
textInput("StockTicker", "Enter Stock Symbol", value = "NFLX"),
sliderInput('periods','Periods',min=1,max=120,value=60),
selectInput("mtvar", "Choose a variable", choices = colnames(mtcars))
))
})
output$mytab12 <- renderUI({
tagList(
conditionalPanel(condition = 'input.tabs=="Switching"',
textInput("StockTicker2", "Enter Stock Symbol", value = "APPL"),
selectInput("cvar", "Choose a variable", choices = colnames(cars))
))
})
output$mytab13 <- renderUI({
tagList(
conditionalPanel(condition = 'input.tabs2=="Tab1"',
textInput("StockTicker3", "Enter Stock Symbol", value = "APPL"),
selectInput("cvar2", "Choose a variable", choices = colnames(cars))
))
})
output$mytab14 <- renderUI({
tagList(
conditionalPanel(condition = 'input.tabs2=="Tab2"',
textInput("StockTicker4", "Enter Stock Symbol", value = "APPL"),
selectInput("cvar3", "Choose a variable", choices = colnames(cars))
))
})
}
)
CodePudding user response:
Try this
library(shiny)
library(shinydashboard)
library(shinydashboardPlus)
shinyApp(
ui = tags$body(class="skin-blue sidebar-mini control-sidebar-open",dashboardPage(
options = list(sidebarExpandOnHover = TRUE),
header = dashboardHeader(title = "Investment Advisor Monitoring - Insider Trading",titleWidth = 450),
sidebar = dashboardSidebar(minified = F, collapsed = F,
h4("Investment Selected"),
#uiOutput("mytab11"),
uiOutput("mytab12"),uiOutput("mytab13"),uiOutput("mytab14")
#textInput("StockTicker3", "Enter Stock Symbol 3", value = "AMZN")
),
body = dashboardBody(
h3('Results'),
tabsetPanel(id = "tabs",
tabPanel("InsiderTraining",
tabsetPanel(id="tabs2",
tabPanel("tab1"),
tabPanel("tab2"))),
tabPanel("Switching"),
tabPanel("Tax Loss Harvesting")
)
),
controlbar = dashboardControlbar(width = 300,
h4("Insider Trading Parameters"),
uiOutput("mytab21"), uiOutput("mytab22")
#selectInput("InsiderTradingModel3", "Insider Trading Model 3",
# c("Dynamic" = "Dynamic",
# "AI based" = "AIbased"))
),
title = "DashboardPage"
)),
server = function(input, output) {
output$mytab11 <- renderUI({
tagList(
conditionalPanel(condition = 'input.tabs=="InsiderTraining"',
textInput("StockTicker", "Enter Stock Symbol", value = "AAPL"),
sliderInput('periods','Periods',min=1,max=120,value=60),
selectInput("mtvar", "Choose a variable", choices = colnames(mtcars))
))
})
output$mytab12 <- renderUI({
tagList(
conditionalPanel(condition = 'input.tabs=="Switching"',
textInput("StockTicker2", "Enter Stock Symbol", value = "NFLX"),
selectInput("cvar", "Choose a variable", choices = colnames(cars))
))
})
output$mytab13 <- renderUI({
tagList(
conditionalPanel(condition = 'input.tabs=="InsiderTraining" && input.tabs2=="tab1"',
textInput("StockTicker3", "Enter Stock Symbol", value = "APPL"),
sliderInput('periods3','Periods',min=1,max=120,value=30),
selectInput("cvar2", "Choose a variable", choices = colnames(cars))
))
})
output$mytab14 <- renderUI({
tagList(
conditionalPanel(condition = 'input.tabs=="InsiderTraining" && input.tabs2=="tab2"',
textInput("StockTicker4", "Enter Stock Symbol", value = "FB"),
selectInput("cvar3", "Choose a variable", choices = colnames(mtcars))
))
})
output$mytab21 <- renderUI({
tagList(
conditionalPanel(condition = 'input.tabs=="Switching"',
textInput("StockTicker", "Enter Stock Symbol", value = "ZM"),
sliderInput('periods','Periods',min=1,max=120,value=80),
selectInput("mtvar", "Choose a variable", choices = colnames(pressure))
))
})
output$mytab22 <- renderUI({
tagList(
conditionalPanel(condition = 'input.tabs=="Tax Loss Harvesting"',
textInput("StockTicker", "Enter Stock Symbol", value = "TSLA"),
sliderInput('periods','Periods',min=1,max=120,value=100),
selectInput("mtvar", "Choose a variable", choices = colnames(iris))
))
})
}
)