Flexdashboard 宽表滚动到侧栏

Tyl*_*ker 5 r shiny flexdashboard

我在Flexdashboard中有一张宽表,通过renderTable. 浏览器中有一个滚动条,但如果您将表格滚动到右侧,它就会进入侧边栏。我怎样才能让它不可见地位于侧边栏后面或将其保留在其 div 单元格中?

这是 MWE:

---
title: 'TEST'
output: 
  flexdashboard::flex_dashboard:
runtime: shiny
---

```{r}
library(flexdashboard)
library(shinyWidgets)
library(shiny)
library(shinyjs)
library(stringi)
```

Inputs {.sidebar  data-width=250} 
-----------------------------------------------------------------------

```{r, echo = FALSE}
fileInput('file_input', tags$b('Choose CSV File'), accept=c('.csv'))
```

Column{data-width=300}
-----------------------------------------------------------------------
```{r, echo = FALSE}

set.seed(10)
x <- unique(stringi::stri_rand_strings(100, 3, '[A-Z]'))
x2 <- setNames(as.data.frame(matrix(sample(1:10, 10*length(x), T), ncol = length(x))), x)

renderTable(x2)
```
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

Mr.*_*ver 6

我们可以使用自定义 CSS 样式和 .sidenav 类来创建我们自己的侧边栏,因为它覆盖了主体的内容,与 .sidebar 不同。然后只需将表格的内容推到右侧,以便侧边栏不会覆盖表格的前几列,我们使用 .table 类中的 margin-left 来完成此操作。在其他属性中添加背景颜色和宽度,使其看起来像您创建的侧边栏。

---
title: 'TEST'
output: 
  flexdashboard::flex_dashboard:
  runtime: shiny
---

```{r}
library(flexdashboard)
library(shinyWidgets)
library(shiny)
library(shinyjs)
library(stringi)
```

Inputs {.sidenav data-width=250} 
-----------------------------------------------------------------------

```{r, echo = FALSE}
fileInput('file_input', tags$b('Choose CSV File'), accept=c('.csv'))
```

Column{data-width=300}
-----------------------------------------------------------------------
```{r, echo = FALSE}

set.seed(10)
x <- unique(stringi::stri_rand_strings(100, 3, '[A-Z]'))
x2 <- setNames(as.data.frame(matrix(sample(1:10, 10*length(x), T), ncol = length(x))), x)

renderTable(x2)
```

<style type="text/css"> 
  .sidenav { 
    overflow-y: hidden;  
    height: 100%;
    width: 250px;
    position: fixed;
    z-index: 1;
    top: 0;
    left: 0;
    background-color: #dde6f0;
    padding-top: 50px;
    padding-right: 10px;
    padding-left: 10px;
  }

  .table {
    margin-left:250px;
  }

</style>

Run Code Online (Sandbox Code Playgroud)

在此输入图像描述