【问题标题】:How to give one flexdashboard page a different sidebar?如何为一个 flexdashboard 页面提供不同的侧边栏?
【发布时间】:2022-01-01 07:53:46
【问题描述】:

我有一个使用 flexdashboard 构建的 rmarkdown 仪表板,其中包含许多输入的全局侧边栏适用于大多数页面,但有一个或两个需要不同的侧边栏。有没有办法只为一个单独的页面覆盖全局侧边栏,或者阻止全局侧边栏在一个特定页面上呈现?

作为示例,以下内容几乎可以让我到达那里,但将全局和本地侧边栏呈现为在第 3 页上重叠,并添加了奇数列的空白。

---
title: "My Page"
output: flexdashboard::flex_dashboard
runtime: shiny
---

Sidebar {.sidebar}
=====================================  

```{r}
checkboxGroupInput(inputId = "options", label = "Some Options:", choices = c("One", "Two", "Three"), selected = c("One", "Two", "Three"))
```

Page 1
=====================================  

Column
-------------------------------------

### Some things here. 

Page 2
=====================================  

Column
-------------------------------------

### Some other things here. 
    
Page 3
=====================================     

Inputs {.sidebar}
-------------------------------------

```{r}
checkboxGroupInput(inputId = "diff_options", label = "Some Different Options:", choices = c("a", "b", "c"), selected = c("a", "b", "c"))
```

Column
-------------------------------------

### Some very different things here. 

看起来像这样。

我知道我可以通过让每个页面都有自己的自定义侧边栏来解决这个问题,但是有很多这样的侧边栏,这会变得相当繁琐。

【问题讨论】:

    标签: css r shiny r-markdown flexdashboard


    【解决方案1】:

    我在最近使用的 shinyApp 中使用了另一个示例。 基本上,您将不同侧边栏的内容放在单独的条件面板中,然后在 tabsetPanel 中添加一个 id。

    在这个应用程序中,每当您更改选项卡时,侧边栏中的选择器都会以编程方式更改

    library(DT)
    library(shiny)
    library(dplyr)
    
    ui <- fluidPage(
      titlePanel("Test"),
      sidebarLayout(
        sidebarPanel(
          conditionalPanel(condition = "input.tabselected==1",
                             selectInput("select_group", label = "Select a Group",
                                         choices = c("Group 1", "Group 2"),
                                         selected = "Group 1")
                           ),
          conditionalPanel(condition = "input.tabselected==2",
                             selectInput("select_group2", label = "Select a Group",
                                         choices = c("Group 3", "Group 4"),
                                         selected = "Group 3")
                           )
        ),
        mainPanel(
          tabsetPanel(
            tabPanel("DataTable", value =1,  DTOutput("my_datatable")),
            tabPanel("Another", value = 2, verbatimTextOutput("text")),
            id="tabselected"
          )
        )
      )
    )
    
    server <- function(input, output){
    
      v <- reactive({
        req(input$select_group)
        if(input$select_group == "Group 1") {
          data <- tibble(`Rows`= paste("Row", 1:4),
                         `Column 1` = rep(0,4))
        } else {
          data <- tibble(`Rows`= paste("Row", 1:5),
                         `Column 1` = rep(0,5))
        }
      })
      
      output$my_datatable <- renderDT({
        req(v())
        DT::datatable(v(), options = list(
          searching = F,
          paging = F,
          ordering = F,
          info = F
          ), editable = TRUE,
          rownames = NULL
        )
      })
    }
    
    shinyApp(ui = ui, server = server)
    

    【讨论】:

    • 这感觉很有希望,但我很难让它在我提供的示例中工作。有什么建议?我试过这个...conditionalPanel(condition = "page_no == 'Page 1'", checkboxGroupInput(inputId = "options1", label = "Some Options:", choices = c("One", "Two", "Three"), selected = c("One", "Two", "Three"))) 但它总是可见的。我想我不知道如何使页面选择成为条件......
    猜你喜欢
    • 2021-03-03
    • 1970-01-01
    • 2018-06-21
    • 1970-01-01
    • 2019-05-17
    • 1970-01-01
    • 2020-06-27
    • 1970-01-01
    • 2017-01-02
    相关资源
    最近更新 更多