简体   繁体   中英

Shiny: How to embed a sidebarPanel inside tabPanel?

I'm trying to have a selecInput panel inside a sepecific tab and I'm not sure how to do that. Inside the function tabPanel() I have tried to include sidebarPanel() right after the function plotOutput () however the sidebarPanel isn't on the side anymore but instead on the left and overlaps the histogram plot. Would there be a way to embed properly that side panel in that particular tab or to get that side panel on the right side of the graph? Thank you, below is the code I use:

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

your concept is right, but placement of code is wrong. Go through following code which is self explanatory.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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