3

I would like to generate a pivot table from rpivotTable library with a vertical scrollbar to allow viewing long outputs.

The pivot table is generated with knitr in RStudio and is embedded in a flexdashboard template.

I am not using shiny dashboard, for which the issue has already been cleared, mine is just a html dashboard generated with knitr.

Before you give me a minus... I really tried, thinking that maybe a setting is undocumented: my part of the Rmd code looks as follows (scroll in both cases brings no result):

---
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}

```

I will be very thankful for any indication how to achieve vertical scrolling of rpivottable.

mnist
  • 6,571
  • 1
  • 18
  • 41
Jacek Kotowski
  • 620
  • 16
  • 49

3 Answers3

4

This is an easier alternative:

  1. Leave the top portion as this:

    ---
    title: "Untitled"
    output: 
      flexdashboard::flex_dashboard:
        orientation: columns
        vertical_layout: fill
    ---
    
  2. Then simply add a CSS chunk after your pivot table chunk, like this:

    .rpivotTable{ overflow : scroll; }
    
  3. This header of the chunk can look like this:

    {css, Pivot Table CSS, echo = FALSE}

Hope this helps!

Lahi S
  • 131
  • 2
  • 7
1

your code is not actually reproducible because we don't have "test2". im trying some generic datasets, but they're not even appearing in the table.

  • I added code to generate fact data. The code will need to be knit to html... but even running chunks of code one can see that large rPivotTable can be scrolled in a vieport, but it cannot be scrolled if embedded in flexdashboard. Thanks for attention. – Jacek Kotowski Oct 12 '16 at 11:30
1

I found the answer that works here: rpivotTable not fitting in my Shiny Dashboard page

In my Rmd file I need in the header a link to a css file:

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

And a styles. css file shall contain

.rpivotTable{ overflow-x: scroll; }

It works like a charm.

Community
  • 1
  • 1
Jacek Kotowski
  • 620
  • 16
  • 49