【问题标题】:Scroll long pivot table (package rpivottable and knitr)滚动长数据透视表(包 rpivottable 和 knitr)
【发布时间】:2017-02-10 17:46:24
【问题描述】:

我想从 rpivotTable 库生成一个数据透视表带有垂直滚动条以允许查看长输出。

数据透视表是在 RStudio 中使用 knitr 生成的,并且 嵌入在 flexdashboard 模板中。

我没有使用闪亮的仪表板,问题已经解决,我的只是使用 knitr 生成的 html 仪表板

在你给我减分之前......我真的试过了,认为可能是一个设置没有记录:我的 Rmd 代码部分如下所示(在两种情况下滚动都没有结果):

---
title: "Untitled"
output: 
  flexdashboard::flex_dashboard:
    orientation: columns
    vertical_layout: fill
---

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

state_table <- data.frame(key=c("CA", "NY", "WA", "ON", "QU"), 
                          name=c("California", "new York", "Washington", "Ontario", "Quebec"), 
                          country=c("USA", "USA", "USA", "Canada", "Canada")) 

month_table <- data.frame(key=1:12, 
                          desc=c("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"), 
                          quarter=c("Q1","Q1","Q1","Q2","Q2","Q2","Q3","Q3","Q3","Q4","Q4","Q4")) 

prod_table <- data.frame(key=c("Printer", "Tablet", "Laptop"), 
                         price=c(225, 570, 1120)) 

# Function to generate the Sales table 

gen_sales <- function(no_of_recs) { # Generate transaction data randomly 
                      loc <- sample(state_table$key, no_of_recs, replace=T, prob=c(2,2,1,1,1)) 
                      time_month <- sample(month_table$key, no_of_recs, replace=T) 
                      time_year <- sample(c(2012, 2013), no_of_recs, replace=T) 
                      prod <- sample(prod_table$key, no_of_recs, replace=T, prob=c(1, 3, 2)) 
                      unit <- sample(c(1,2), no_of_recs, replace=T, prob=c(10, 3)) 
                      amount <- unit*prod_table[prod,]$price 

                      sales <- data.frame(month=time_month, 
                                          year=time_year, 
                                          loc=loc, 
                                          prod=prod, 
                                          unit=unit, 
                                          amount=amount) 

                      # Sort the records by time order 

                      sales <- sales[order(sales$year, sales$month),] 

                      row.names(sales) <- NULL 
                      return(sales) 
} 

# Now create the sales fact table 

sales_fact <- gen_sales(100000) 


```

Column {data-width=650}
-----------------------------------------------------------------------

### Table

```{r}
library(rpivotTable)
rpivotTable(
sales_fact,
rows = c("year","month"),
cols = c("prod"),
aggregatorName = "Sum",
vals = "amount",
rendererName = "Heatmap",
height = "600px",
overflow = "scroll")

```

Column {data-width=350}
-----------------------------------------------------------------------

### Chart B

```{r}

```

### Chart C

```{r}

```

我将非常感谢任何指示如何实现 rpivottable 的垂直滚动。

【问题讨论】:

    标签: css r r-markdown flexdashboard rpivottable


    【解决方案1】:

    这是一个更简单的选择:

    1. 将顶部保留为:

      ---
      title: "Untitled"
      output: 
        flexdashboard::flex_dashboard:
          orientation: columns
          vertical_layout: fill
      ---
      
    2. 然后只需在数据透视表块之后添加一个 CSS 块,如下所示:

      .rpivotTable{ overflow : scroll; }
      
    3. 这个块的头部可以是这样的:

      {css, 数据透视表 CSS, echo = FALSE}

    希望这会有所帮助!

    【讨论】:

      【解决方案2】:

      您的代码实际上不可重现,因为我们没有“test2”。我正在尝试一些通用数据集,但它们甚至没有出现在表格中。

      【讨论】:

      • 我添加了代码来生成事实数据。代码需要被编织到 html ......但即使运行代码块也可以看到大型 rPivotTable 可以在视口中滚动,但如果嵌入到 flexdashboard 中则无法滚动。感谢关注。
      【解决方案3】:

      我在这里找到了有效的答案:rpivotTable not fitting in my Shiny Dashboard page

      在我的 Rmd 文件中,我需要在标题中添加一个指向 css 文件的链接:

      ---
      title: "Untitled"
      output: 
        flexdashboard::flex_dashboard:
          css: styles.css
          orientation: columns
          vertical_layout: fill
      ---
      

      还有一个样式。 css 文件应包含

      .rpivotTable{ overflow-x: scroll; }
      

      它就像一个魅力。

      【讨论】:

        猜你喜欢
        • 2017-04-21
        • 2023-04-06
        • 2018-09-02
        • 1970-01-01
        • 2020-11-24
        • 2021-08-24
        • 1970-01-01
        • 2021-07-02
        • 1970-01-01
        相关资源
        最近更新 更多