【发布时间】: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。 -
非常感谢尼尔森,我已经用我的实际问题更新了这个问题。