繁体   English   中英

Shiny:如何在tabPanel中嵌入sidebarPanel?

[英]Shiny: How to embed a sidebarPanel inside tabPanel?

我试图在一个特定的选项卡中有一个selecInput面板,我不知道该怎么做。 在函数tabPanel()内部,我试图在函数plotOutput()之后包含sidebarPanel(),但是sidebarPanel不再在侧面,而是在左侧并重叠直方图。 是否有办法在该特定标签中正确嵌入该侧面板或将该侧面板放在图表的右侧? 谢谢,下面是我使用的代码:

mainPanel(
    tabsetPanel(
      tabPanel("Histogram",plotOutput("histogram")),
      tabPanel("Scatter",plotOutput("scatter"),
               sidebarPanel(
  selectInput("xaxis", label = "x axis",
              choices = detectors, selected = detectors[1],width='200px',selectize=FALSE),
  selectInput("yaxis", label = "y axis",
              choices = detectors, selected = detectors[2],width='200px',selectize=FALSE),
  selectInput("population1", label = "Population 1",
              choices = files, selected = files[1],width='200px',selectize=FALSE),
  selectInput("population2", label = "Population 2",
              choices = files, selected = files[1],width='200px',selectize=FALSE),
  selectInput("population3", label = "Population 3",
              choices = files, selected = files[1],width='200px',selectize=FALSE)
  )
),
      tabPanel("Table", DT::dataTableOutput("table"))
    )
)

你的概念是正确的,但代码的放置是错误的。 通过以下代码进行解释。

library(shiny)
ui <- fluidPage(


   titlePanel("Old Faithful Geyser Data"),

   tabsetPanel(               
           tabPanel("Tab 1", h1("First tab") ),
           tabPanel("Tab2",
             sidebarLayout(
               sidebarPanel(width = 3, sliderInput("bins",
                                                   "Number of bins:",
                                                   min = 1,
                                                   max = 50,
                                                   value = 30)
               ),

               mainPanel(
                 plotOutput("distPlot")
             )
           )
       )
   )
)
server <- function(input, output) {

   output$distPlot <- renderPlot({
      x    <- faithful[, 2] 
      bins <- seq(min(x), max(x), length.out = input$bins + 1)

      hist(x, breaks = bins, col = 'darkgray', border = 'white')
   })
}
shinyApp(ui = ui, server = server)*

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM