r - 在闪亮的应用程序中为嵌套在其他 tabsetPanel() 中的 tabsetPanel() 创建不同的侧边栏
问题描述
我在下面有一个闪亮的应用程序,带有 3 个不同的选项卡。我希望每个选项卡都有自己的侧边栏,我使用conditionalPanel()
. 虽然第一个选项卡 ( InsiderTraining
) 里面还有 2 个选项卡 ( Tab1,Tab2
),但我也希望有单独的侧边栏。
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))
))
})
}
)
解决方案
尝试这个
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))
))
})
}
)
推荐阅读
- ruby - 对破折号小部件进行故障排除
- r - 有没有办法创建一个没有聚合值的子集数据透视表?
- mysql - 需要从 MySQL 中获取行
- javascript - PhpStorm 无法识别 webpack 别名
- node.js - 控制器中的快速路由未解决
- intel - 英特尔 VT-x:如何将 NMI 交付给客户操作系统
- python - 尝试在 AWS Lambda 中使用 Pillow 时无法导入名称“_imaging”
- linux - Linux 中的 Spring Data GemFire 服务器 java.net.BindException
- javascript - 动态更新父状态
- java - 使用 Jackson 解析 XML 时如何忽略特定节点