使用navbarPage设计sidebarPanel

时间:2017-10-31 09:53:21

标签: r shiny

我有这个UI myUI

(可复制代码):

library(shiny)

ui <- fluidPage(
  sidebarPanel(
    tabsetPanel(
      tabPanel("tab1", checkboxInput("opt1", "opt1 for 1 tab")),
      tabPanel("tab2", checkboxInput("opt2", "opt2 for 2 tab"))
    )
  ),
  mainPanel(
    navbarPage("choose page",
      navbarMenu("page1", 
                 tabPanel("panel1", 
                          mainPanel(plotOutput("plot1"))
                          ), 
                 tabPanel("panel2", plotOutput("plot2"))
                 ),


      navbarMenu("page2", tabPanel("panel3", plotOutput("plot3")), tabPanel("panel4", plotOutput("plot4")))
    )
  )
)


server <- function(input, output){

}

shinyApp(ui, server)

我想在sidebarPanel中添加:

  1. checkboxInput仅适用于page1panel1
  2. 仅对page1 {常见于panel1panel2
  3. 的复选框输入

    有可能闪亮吗?

2 个答案:

答案 0 :(得分:1)

是的,将id添加到navbarPage并使用conditionalPanel

ui <- fluidPage(
  sidebarPanel(
    conditionalPanel(
      'input.navbar == "panel1"',
      checkboxInput("checkbox1", "Hello")
    ),
    conditionalPanel(
      'input.navbar == "panel1" || input.navbar == "panel2"',
      checkboxInput("checkbox1", "Goodbye")
    )
  ),
  mainPanel(
    navbarPage("choose page",
               navbarMenu("page1", 
                          tabPanel("panel1", 
                                   mainPanel(plotOutput("plot1"))
                          ), 
                          tabPanel("panel2", plotOutput("plot2"))
               ),
               navbarMenu("page2", tabPanel("panel3", plotOutput("plot3")), tabPanel("panel4", plotOutput("plot4"))),
               id = "navbar"
    )
  )
)

答案 1 :(得分:-1)

为什么它不能正常工作?

library(shiny)

ui <- fluidPage(
  navbarPage("Choose page: " ,
    navbarMenu("Discovering the dataset",
      sidebarPanel(
                  checkboxInput("x", "x")
      ),

                tabPanel("volume", mainPanel(plotOutput("pp"))),
                tabPanel("amount salary"),
                tabPanel("map"),
                tabPanel("data"),
                tabPanel("animation"),
                tabPanel("wordcloud")

    ),
    navbarMenu("Options"),
    navbarMenu("More information")

)
)


server <- function(input, output){
  output$pp <- reactivePlot({plot(1,1)})
}

shinyApp(ui, server)

这里我想要所有barpage Discovering the dataset

的复选框