【问题标题】:Shiny: How to embed a sidebarPanel inside tabPanel?Shiny:如何在 tabPanel 中嵌入 sidebarPanel?
【发布时间】:2016-07-21 20:10:34
【问题描述】:

我正在尝试在特定选项卡内设置一个 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"))
    )
)

【问题讨论】:

  • 仅使用部分代码很难理解输出。如果您提供一个服务器和 UI 的最小可重现示例,那就更好了。
  • 您似乎没有在任何地方调用 sideBarLayout()...
  • sideBarLayout() 是我想要的。简单,谢谢!

标签: r shiny markdown


【解决方案1】:

您的概念是正确的,但代码的位置是错误的。浏览以下不言自明的代码。

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-01-16
    • 2014-06-08
    • 2017-06-04
    • 1970-01-01
    • 2016-08-23
    • 2016-11-25
    • 2021-04-24
    • 1970-01-01
    相关资源
    最近更新 更多