ShinyApp 中的多个选项卡

Multiple tabs in ShinyApp

此代码为我提供了一个选项卡。我希望能够向其添加更多选项卡以制作一些图,使用聚合函数可能是。我厌倦了在我的 tabsetPanel( 中添加第二个 tabPanel( 对象,但没有成功。

如果有人能帮助我,我将不胜感激

library(shiny)
library(dplyr)


ui <- fluidPage(
  tabsetPanel(
    tabPanel("Table", fluid = TRUE,
  sidebarLayout(position = "left",
                sidebarPanel("sidebar panel",
                             selectInput(inputId = "table",
                                         label = "Choose a Supplier",
                                         "Names"),
                             actionButton(inputId = "btn",label="Update")
                ),
                mainPanel("main panel",
                          tableOutput("myTable")
                )))
  
  ))
server <- function(input, output,session)
{
  GlassSupplier <- c('Supplier 1','Supplier 2','Supplier 1','Supplier 4','Supplier 2')
  WindowType <- c('Wood','Vinyl','Aluminum','Aluminum','Vinyl')
  BreakageRate <- c(7.22,6.33,3.63,2,6)
  df<- data.frame(GlassSupplier,WindowType,BreakageRate)
  data <- eventReactive(input$btn, {
    req(input$table)
    df %>% dplyr::filter(GlassSupplier %in% input$table) %>%
      group_by(WindowType) %>%
      dplyr::summarise(BrkRate = mean(BreakageRate))
  })
  
  #Update SelectInput Dynamically
  observe({
    updateSelectInput(session, "table", choices = df$GlassSupplier)
  })
  
  output$myTable = renderTable({
    data()
  })
}
shinyApp(ui,server)


tabsetPanel 视为任何其他 slider/button,您可以将其插入边栏内、主面板中或 sidebarLayout.

之前

ui 代码:

u <- shinyUI(fluidPage(
  titlePanel("title panel"),
  sidebarLayout(position = "left",
                sidebarPanel("sidebar panel",
                             selectInput(inputId = "table",
                                         label = "Choose a Supplier",
                                         "Names"),
                             actionButton(inputId = "btn",label="See Table"),
                             checkboxInput("donum1", "Make #1 plot", value = T),
                             checkboxInput("donum2", "Make #2 plot", value = F),
                             checkboxInput("donum3", "Make #3 plot", value = F),
                             checkboxInput("donum4", "Make #4 plot", value = F),
                             sliderInput("wt1","Weight 1",min=1,max=10,value=1),
                             sliderInput("wt2","Weight 2",min=1,max=10,value=1),
                             sliderInput("wt3","Weight 3",min=1,max=10,value=1),
                             sliderInput("wt4","Weight 4",min=1,max=10,value=1)
                ),
                mainPanel("main panel",
                          tabsetPanel(
                          tabPanel("Plot", column(6,plotOutput(outputId="plotgraph", width="500px",height="400px"))),
                          tabPanel('Table', tableOutput("myTable")))
                ))))