使用动态生成的tabPanel构建tabBox,但使用自定义UI args

时间:2017-11-21 16:45:15

标签: r shiny shinydashboard

我需要一些帮助来解决我试图解决的这个特殊问题。以下是我希望该功能的用途:

  1. 用户将从下拉列表中选择一些内容(selectInput)。
  2. 服务器将根据选择提取指标。我们称之为 gameMetrics
  3. 服务器将从 gameMetrics 构建tabPanel,并在 width = NULL 的tabBox中呈现它们。
  4. 以下是我的尝试:

    尝试1

    server.R

    output$gameMetricsPanels <- renderUI({
        # gameMetrics is a data frame of games and metrics being measured
        # input$gameSelected is the value that is selected by the user from the dropdown
    
        currentGame <- get_game_code(gameMetrics, input$gameSelected)
    
        # get_metric_groups will return a list of metrics for the selected game
        gameMetricGroups <- get_metric_groups(gameMetrics, currentGame)
    
        tabs <- lapply(tools::toTitleCase(gameMetricGroups), tabPanel)
    
        do.call(tabBox, tabs)
    

    ui.R

    ui <- dashboardPage(
        shinyHeader, # stuff I have for header
        shinySidebar, # stuff I have for sidebar
        dashboardBody(
            tabItems(
                tabItem(
                    tabName = "dashboard",
                        fluidRow(
                            column(
                                12,
                                uiOutput("gameMetricsPanels")
                            )
                        )
                    )
                )
            )
        )
    )
    

    为什么这种方法没有按预期工作:

    因为tabBox有一个默认的 width = 6 ,我无法用 do.call 来控制它。我不是R专家,谷歌搜索并没有真正帮助。

    尝试2

    server.R

    output$gameMetricsPanels <- renderUI({
        # gameMetrics is a data frame of games and metrics being measured
        # input$gameSelected is the value that is selected by the user from the dropdown
    
        currentGame <- get_game_code(gameMetrics, input$gameSelected)
    
        # get_metric_groups will return a list of metrics for the selected game
        gameMetricGroups <- get_metric_groups(gameMetrics, currentGame)
    
        tabs <- list(NULL)
    
        for (gameMetricGroup in gameMetricGroups) {
            tab <- tabPanel(toosl::toTitleCase(gameMetricGroup), value = gameMetricGroup)
            tabs <<- c(tabs, tab)
        }
    
        return(tabs)
    

    ui.R

    # stuff similar to above attempt but without the crazy nesting for readability
    fluidRow(
        column(
            12,
            tabBox(  # Here, the main difference is that I'm wrapping the uiOutput in tabBox but I don't know if that's allowed
                id = "tabMetrics",
                width = NULL,  # enforce width to match parent container
                uiOutput("gameMetricsPanels")
            )
        )
    )
    

    为什么这种方法不起作用:

    没有任何内容显示为标签...

0 个答案:

没有答案