闪亮:如何在选项卡面板内嵌入一个侧边栏面板?

8

我试图在特定选项卡内放置一个selectInput面板,但我不确定该如何实现。在函数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"))
    )
)

仅凭部分代码很难理解输出结果。最好提供一个最小可重现的示例,包括服务器和用户界面。 - Molx
你似乎没有在任何地方调用sideBarLayout()函数... - Stuart R. Jefferys
sideBarLayout() 是我正在寻找的。简单易懂,谢谢! - Matthieu Delcourt
1个回答

7

你的概念是正确的,但代码的放置位置是错误的。请查看以下代码,其中已经自我说明。

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)

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接