【问题标题】:Multiple tabs in ShinyAppMultiple tabs in ShinyApp
【发布时间】:2021-12-31 16:01:16
【问题描述】:

这段代码给了我一个标签。我希望能够向它添加更多选项卡以制作一些绘图,使用聚合函数可能是。我厌倦了在我的 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)


【问题讨论】:

  • 有什么特别的理由在面板内有一个侧边栏而不是相反?
  • 其实我刚开始学习R,不知道最好的方法是什么
  • 您可以添加另一个面板和另一个带有标题的tabsetPanel
  • 非常感谢尼尔森,我已经用我的实际问题更新了这个问题。

标签: r shiny shinyapps


【解决方案1】:

tabsetPanel 视为任何其他滑块/按钮,您可以将其插入侧边栏、主面板或sidebarLayout 之前。

用户界面代码:

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

【讨论】:

    猜你喜欢
    • 2016-12-04
    • 2022-12-01
    • 2022-12-02
    • 2022-12-28
    • 2022-12-01
    • 2022-12-26
    • 2022-12-27
    • 1970-01-01
    • 2022-12-01
    相关资源
    最近更新 更多