【问题标题】:Create different sidebars for tabsetPanel() nested in other tabsetPanel() in a shiny app在闪亮的应用程序中为嵌套在其他 tabsetPanel() 中的 tabsetPanel() 创建不同的侧边栏
【发布时间】:2021-12-17 03:38:14
【问题描述】:

我在下面有一个闪亮的应用程序,带有 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))
        ))
    }) 
    
  }
)

【问题讨论】:

    标签: r shiny


    【解决方案1】:

    试试这个

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

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-08-18
    • 2020-01-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多