【问题标题】:How to extend the renderTable width in Shiny flexdashboard如何在 Shiny flexdashboard 中扩展 renderTable 的宽度
【发布时间】:2017-10-28 03:07:57
【问题描述】:

我有以下自包含 Shiny-Flexdashboard:

---
title: "FOO"
runtime: shiny
output: 
  flexdashboard::flex_dashboard:
    vertical_layout: scroll
    orientation: rows
    theme:   default

---

```{r setup, include=FALSE}
library(flexdashboard)
library(tidyverse)
```

Rows
-------------------------------------

### Statistical Test Summary
```{r stat_test_table}
mainPanel(

  renderTable( {
      dat <- df <- structure(list(`Sample name` = structure(1:3, .Label = c("Sample1", 
          "Sample2", "Sample3"), class = "factor"), `FDR correction (mean)` = c(5.93070861978308e-15, 
         6.88632524238004e-13, 3.28339498763286e-16), `FDR correction (sd)` = c(2.00046170407461e-14, 
        2.32019633515427e-12, 1.10782095003689e-15), `P-value (mean)` = c(5.55365134900322e-15, 
        6.44757191496266e-13, 3.07475941705412e-16), `P-value (sd)` = c(1.98732517127302e-14, 
        2.30494707691577e-12, 1.10054774779699e-15)), class = c("tbl_df", 
        "tbl", "data.frame"), .Names = c("Sample name", "FDR correction (mean)", 
        "FDR correction (sd)", "P-value (mean)", "P-value (sd)"), row.names = c(NA,  -3L))
  }
  , digits=-2, width = '100%'
  )
)
```

它会生成这样的表格:

如前所述,如何扩展列宽?

【问题讨论】:

  • set width = '200%' 也可以解决问题。
  • 连同orientation : columns in output in markdown header

标签: r shiny r-markdown flexdashboard


【解决方案1】:

有趣。如果您查看?mainPanel() 的文档。您将看到宽度默认限制为“8”(最大为 12): mainPanel(..., width = 8)

因此,如果您简单地更改为: mainPanel(..., width = 12) 会起作用的。

【讨论】:

【解决方案2】:

mainPanel 中使用width = 12 并在div 中包含表格就可以了。

---
title: "FOO"
runtime: shiny
output: 
  flexdashboard::flex_dashboard:
    vertical_layout: scroll
    orientation: columns
    theme:   default

---

```{r setup, include=FALSE}
library(flexdashboard)
library(tidyverse)
```

Columns
-------------------------------------

### Statistical Test Summary
```{r stat_test_table}

mainPanel(width = 12,
  div(style="height:570px",
  renderTable( {
      dat <- df <- structure(list(`Sample name` = structure(1:3, .Label = c("Sample1", 
          "Sample2", "Sample3"), class = "factor"), `FDR correction (mean)` = c(5.93070861978308e-15, 
         6.88632524238004e-13, 3.28339498763286e-16), `FDR correction (sd)` = c(2.00046170407461e-14, 
        2.32019633515427e-12, 1.10782095003689e-15), `P-value (mean)` = c(5.55365134900322e-15, 
        6.44757191496266e-13, 3.07475941705412e-16), `P-value (sd)` = c(1.98732517127302e-14, 
        2.30494707691577e-12, 1.10054774779699e-15)), class = c("tbl_df", 
        "tbl", "data.frame"), .Names = c("Sample name", "FDR correction (mean)", 
        "FDR correction (sd)", "P-value (mean)", "P-value (sd)"), row.names = c(NA,  -3L))
  }
  , digits=-2, width = '100%'
  ))
)
```

它产生的输出为:

【讨论】:

    【解决方案3】:

    我认为重要的是要注意mainPanel 不是为您的用例而设计的。这是mainPanel 的“正确”用法以及为什么会有默认的width = 8

    sidebarLayout(
      sidebarPanel(sliderInput("thing", "Thing", min = 0, max = 5, value = 4)),
      mainPanel(
        renderDataTable( {
    
        input$Thing
          dat <- df <- structure(list(`Sample name` = structure(1:3, .Label = c("Sample1", 
              "Sample2", "Sample3"), class = "factor"), `FDR correction (mean)` = c(5.93070861978308e-15, 
             6.88632524238004e-13, 3.28339498763286e-16), `FDR correction (sd)` = c(2.00046170407461e-14, 
            2.32019633515427e-12, 1.10782095003689e-15), `P-value (mean)` = c(5.55365134900322e-15, 
            6.44757191496266e-13, 3.07475941705412e-16), `P-value (sd)` = c(1.98732517127302e-14, 
            2.30494707691577e-12, 1.10054774779699e-15)), class = c("tbl_df", 
            "tbl", "data.frame"), .Names = c("Sample name", "FDR correction (mean)", 
            "FDR correction (sd)", "P-value (mean)", "P-value (sd)"), row.names = c(NA,  -3L))
      }
      )
      )
    )
    

    此外,如果您使用 DT::renderDataTable,您的表格将更加灵活,您可以在此处阅读 https://rstudio.github.io/DT/

    事实上,默认情况下,这会占用浏览器窗口宽度的 100%,而不需要包装器。您可以考虑在 flexdashboards 中使用 fillPagefluidPage 来控制专用于各个元素的大小/区域。

    ---
    title: "FOO"
    runtime: shiny
    output: 
      flexdashboard::flex_dashboard:
        vertical_layout: scroll
        orientation: rows
        theme:   default
    
    ---
    
    ```{r setup, include=FALSE}
    library(flexdashboard)
    library(tidyverse)
    library(DT)
    ```
    
    Rows
    -------------------------------------
    
    ### Statistical Test Summary
    
    ```{r}
    DT::renderDataTable( {
    
        input$Thing
          dat <- df <- structure(list(`Sample name` = structure(1:3, .Label = c("Sample1", 
              "Sample2", "Sample3"), class = "factor"), `FDR correction (mean)` = c(5.93070861978308e-15, 
             6.88632524238004e-13, 3.28339498763286e-16), `FDR correction (sd)` = c(2.00046170407461e-14, 
            2.32019633515427e-12, 1.10782095003689e-15), `P-value (mean)` = c(5.55365134900322e-15, 
            6.44757191496266e-13, 3.07475941705412e-16), `P-value (sd)` = c(1.98732517127302e-14, 
            2.30494707691577e-12, 1.10054774779699e-15)), class = c("tbl_df", 
            "tbl", "data.frame"), .Names = c("Sample name", "FDR correction (mean)", 
            "FDR correction (sd)", "P-value (mean)", "P-value (sd)"), row.names = c(NA,  -3L))
      },
      extensions = "Responsive"
      )
    ```
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-05-14
      • 1970-01-01
      • 2021-10-20
      • 1970-01-01
      • 1970-01-01
      • 2017-12-06
      • 1970-01-01
      相关资源
      最近更新 更多